0

我有一个片段,在正常启动时会显示一个地图视图,当前用户位置显示为蓝点标记。我有一个功能可以从另一个地方启动这个屏幕,并且可以传递纬度和经度值。基于这些值,我更新了“MapboxMap”的经纬度。该位置会在地图上更新,并且相机会缩放到该位置,但蓝点标记仍显示为用户当前位置。如何更新蓝点标记以显示为由纬度和经度值给出的新位置:

我更新位置的代码:

private void goToUserLocation() {

        double requestedLatitude = 0;
        double requestedLongitude = 0;

        if (mapboxMap == null || !getUserVisibleHint()) {
            return;
        }
        if (!DeviceUtil.isLocationServiceEnabled(getContext().getApplicationContext())) {
            showLocationDisabledSnackbar();
            return;
        }
        enableUserLocationMarker();
        Location location = mapboxMap.getMyLocation();
        //Get the requested coordinates if it exists
        if(location != null) {
            try {
                Uri intentData = getActivity().getIntent().getData();
                if (null != intentData) {
                    String latitude = intentData.getQueryParameter("lat");
                    String longitude = intentData.getQueryParameter("lon");

                    if (!TextUtils.isEmpty(latitude) && !TextUtils.isEmpty(longitude)) {

                            requestedLatitude = Double.parseDouble(latitude);
                            requestedLongitude = Double.parseDouble(longitude);

                            if ((requestedLatitude >= -90 && requestedLatitude <= 90) &&
                                    (requestedLongitude >= -90d && requestedLongitude <= 90d)) {
                                location.setLatitude(requestedLatitude);
                                location.setLongitude(requestedLongitude);
                            }
                    }

                }
            }catch (NumberFormatException ex) {

            }
            finally {
                goToLocation(location);
            }
        }
        fetchNearbyPages();
    }

任何帮助表示赞赏。

4

1 回答 1

0

嗨希望这会有所帮助。

首先,重写 onLocatioChanged 方法并将更新的位置传递给单独创建的 setCameraToCurrentPosition 方法。前任。如下:-

public void onLocationChanged(Location location) {
    setCameraToCurrentPosition(Location location);
}

private void setCameraToCurrentPosition(Location location) {
    setCameraPosition(new LatLng(location.getLatitude(), location.getLongitude()), 16, 6500);

    // Here you need to add the marker to current position of user on map.

}
于 2018-01-18T05:27:18.053 回答