2017-01-31 46 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的

相关问题