【问题标题】:How to update the blue dot marker for current location in MapView in Android如何在 Android 的 MapView 中更新当前位置的蓝点标记
【发布时间】:2018-01-31 03:09:09
【问题描述】:

我有一个片段,正常启动时会显示一个地图视图,当前用户位置显示为蓝点标记。我有一个功能可以从另一个地方启动这个屏幕,并且可以传递纬度和经度值。基于这些值,我更新了“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();
    }

感谢任何帮助。

【问题讨论】:

    标签: android android-mapview mapbox-marker


    【解决方案1】:

    您好,希望这会有所帮助。

    首先,重写 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.
    
    }
    

    【讨论】:

      猜你喜欢
      • 2017-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-16
      • 2019-03-28
      • 1970-01-01
      • 2014-04-23
      • 1970-01-01
      相关资源
      最近更新 更多