1

我是新来的Skobbler map。在我Skobbler map的方法中,我正在获取我当前的位置onCurrentPositionUpdate

SKCoordinateRegion region = new SKCoordinateRegion();
        region.setCenter(currentPosition.getCoordinate());
        region.setZoomLevel(13);
        mapView.changeMapVisibleRegion(region, true);

因此,它显示了我当前的位置。

在此处输入图像描述

当我通过像这样拖动地图从当前位置移动一段距离时:

在此处输入图像描述

但是,在 4 或 5 秒后,它立即返回到我当前的位置。可以做些什么来停止这种运动,因为我只想在按下按钮后返回我当前的位置。在我的按钮中,我使用:

 @OnClick(R.id.fab_gps)
    public void goToMyGpsLocation(View view) {
        if (mapView != null && currentPosition != null) {
            mapView.getMapSettings().setCurrentPositionShown(true);
       } else{
            if(Helper.isGPSEnabled(this)){
                requestCurrentPositionProvider();
           }else{
                Helper.alertbox("GPS not enabled", "Please enable gps before you are directed to your current location", this);
            }
        }
    }

在我的requestCurrentPositionProvider方法中:

public void requestCurrentPositionProvider(){


        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
                != PackageManager.PERMISSION_GRANTED) {
            Permissions.requestPermission(this, LOCATION_PERMISSION_REQUEST_CODE,
                    Manifest.permission.ACCESS_FINE_LOCATION, true);
        } else{
            if(mapView != null) {
                mapView.getMapSettings().setCurrentPositionShown(true);

            }
            if(Helper.isGPSEnabled(this)){
                showSnackBar(findViewById(android.R.id.content));

                currentPositionProvider = new SKCurrentPositionProvider(this);
                currentPositionProvider.setCurrentPositionListener(this);
                currentPositionProvider.requestLocationUpdates(MapUtils.hasGpsModule(this), MapUtils.hasNetworkModule(this), false);

            }

            else {
             Helper.alertbox("GPS not enabled", "Please enable gps before you are directed to your current location", this);
                }

诸如运动之类的东西Camera变化如此之快。我该如何阻止它?可以在onClick方法上做什么,以便仅在按下按钮后返回当前位置?

4

2 回答 2

0

我了解到您的onCurrentPositionUpdate()方法包含:

SKCoordinateRegion region = new SKCoordinateRegion();
region.setCenter(currentPosition.getCoordinate());
region.setZoomLevel(13);
mapView.changeMapVisibleRegion(region, true);

这当然会根据您的当前位置在每个“当前位置更新”(即位置更新)上将地图视图居中。

您已请求 GPS 位置更新。如果我理解正确,这些将触发该onCurrentPositionUpdate()方法。(从代码片段中并没有真正看到,但这不是 Skobbler 地图应用程序的工作方式......)

即使您实际上没有移动,GPS 位置也可能会出现一些波动,并且该方法可能每隔几秒就会被调用一次。

如果您同时拖动了地图,它将在每次 GPS 位置更新时居中回到“当前位置”。

因此,如果您想保持手动选择的地图状态,请不要在onCurrentPositionUpdate().

于 2016-10-05T12:36:24.593 回答
0
mapView.animateCamera(CameraUpdateFactory.zoomTo(16), 5000, null);

这有助于为您的相机设置 5 秒的动画,您可以根据需要更改时间。

否则试试这个

mapView.animateToLocation(new SKCoordinate(37.7765, -122.4200), 5000);
于 2016-10-05T11:06:59.383 回答