2016-10-05 39 views
1

我是Skobbler map的全新產品。在我的Skobbler map中,我正在使用onCurrentPositionUpdate方法獲取當前位置。位置從特定位置立即更改爲我在Skobbler地圖中的當前位置

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

因此,它顯示我的當前位置。

enter image description here

當我通過拖動地圖這樣的移動從我目前的位置有一定距離:

enter image description here

但是,很少有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方法可以做些什麼,以便在按下按鈕後返回當前位置?

回答

0
mapView.animateCamera(CameraUpdateFactory.zoomTo(16), 5000, null); 

這有助於動畫您的相機5秒鐘,您可以根據您的要求更改時間。

別的嘗試這個

mapView.animateToLocation(new SKCoordinate(37.7765, -122.4200), 5000); 
+0

我在哪裏使用它?在'onCreate'或某處。 –

+0

mapView.changeMapVisibleRegion(region,true);在此代碼下面添加它 – raasesh

+0

無法解析animateCamera方法。我現在能做什麼 ? –

0

我明白你的onCurrentPositionUpdate()方法包括:

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

這當然根據每個「當前位置更新」您當前所在位置爲中心的地圖視圖,即位置更新。

您已經申請GPS位置更新。如果我已經正確理解,那麼將觸發onCurrentPositionUpdate()方法。 (從代碼片段中看不到,但並不是說Skobbler地圖應用程序的工作原理...)

即使您沒有實際移動,GPS位置和方法可能會有一些波動可能每隔幾秒鐘就會被呼叫。

如果您在此期間拖動了地圖,它將會在每個GPS位置更新中居中回到「當前位置」。

因此,如果您想保留手動選擇的地圖狀態,請不要總是將它居中置於onCurrentPositionUpdate()中每個位置更新的真實當前位置。