2017-01-31 41 views
0

我在網上做了相當多的研究,但是我無法找到關於此主題的任何內容。 Anywho,我有一個地圖,找到devices'current的位置,這是代碼:將地圖居中放置在設備當前位置,沒有「中央按鈕」

 mMap.setMyLocationEnabled(false); 
     mMap.getUiSettings().setMyLocationButtonEnabled(false); 

我禁用了中心到設備的位置button;有沒有辦法在沒有按鈕的情況下將地圖居中?所以當地圖加載時它會自動居中設備的位置。

回答

0

那麼按鈕的功能是它可以找到你當前的緯度和經度,並根據它來修正地圖相機的位置。如果你知道lat和長要居中,那麼你可以使用下面的代碼的位置 -

CameraPosition target; 
latLngTemp = new LatLng(-36.84490439080399, 174.76745902901663); 
       target = CameraPosition.builder().target(latLngTemp).zoom(10).build(); 
mMap.moveCamera(CameraUpdateFactory.newCameraPosition(target)); 

所以現在在設備屏幕中心地圖上的上述統籌

0

您可以使用下面的代碼

CameraPosition cameraPosition = new CameraPosition.Builder() 
     .target(new LatLng(/*current latitude*/location.getLatitude(), /*current longitude*/location.getLongitude()))  // Sets the center of the map to location user 
     .zoom(17)     // Sets the zoom 
     .build();     // Creates a CameraPosition from the builder 
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); 

對於更多信息,請訪問https://developers.google.com/maps/documentation/android-api/views

0

你應該實現LocationListener的獲得位置更新。在您的onLocationChanged(位置定位)中心,你的相機像這樣

@Override 
public void onLocationChanged(Location location) { 
    map.animateCamera(CameraUpdateFactory.newCameraPosition(new LatLong(location.getLatitude(), location.getLongitude())); 
} 

看到這個link實施LocationListener的

相關問題