2016-08-07 153 views
1

我想在谷歌地圖上顯示當前位置andorid.I已經寫了一些鱈魚做到這一點。但是當我在地圖活動上啓動應用程序時,它不顯示谷歌地圖上的當前位置。但是當我點擊當前位置谷歌地圖上的按鈕,然後顯示當前位置。請問爲什麼它不會自動顯示當前位置?無法自動顯示谷歌地圖上的當前位置?

mMap.setMyLocationEnabled(true); 
       mMap.getUiSettings().setMyLocationButtonEnabled(true); 
       Log.i("MAP", "AFTER LOCATION"); 
       LocationManager locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE); 
       Criteria criteria = new Criteria(); 
       criteria.setAccuracy(Criteria.ACCURACY_FINE); 
       String bestProvider = locationManager.getBestProvider(criteria, true); 
       Location location = locationManager.getLastKnownLocation(bestProvider); 
       if (location != null) { 

        onLocationChanged(location); 
       } 
       locationManager.requestLocationUpdates(bestProvider,0, 0, this); 

enter image description here

回答

0

使用此功能,在地圖準備:

private void centerMap(GoogleMap map, Double latitude, Double longitude){ 

    LatLng latLng = new LatLng(latitude, longitude); 

    CameraPosition cp = new CameraPosition.Builder() 
      .target(latLng) 
      .zoom(13) 
      .build(); 

    map.animateCamera(CameraUpdateFactory.newCameraPosition(cp)); 
} 

你可以從位置座標如下:location.getLatitude()和Location.getLongitude()

+0

它是否被覆蓋的方法? – Techiee

+0

nope,我寫道,但你可以自由使用它;) – Panczur

+0

仍然無法正常工作。請幫助更多 – Techiee

相關問題