How do I zoom in automatically to the current location in Google Maps API for Android?

北慕城南 提交于 2019-12-03 23:33:37

Change from:

mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));

to:

float zoomLevel = 16.0f; //This goes up to 21
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoomLevel));

public static CameraUpdate newLatLngZoom (LatLng latLng, float zoom)

Returns a CameraUpdate that moves the center of the screen to a latitude and longitude specified by a LatLng object, and moves to the given zoom level.

Parameters latLng a LatLng object containing the desired latitude and longitude. zoom the desired zoom level, in the range of 2.0 to 21.0. Values below this range are set to 2.0, and values above it are set to 21.0. Increase the value to zoom in. Not all areas have tiles at the largest zoom levels. Returns a CameraUpdate containing the transformation.

or you can also use animateCamerma method to get an animated zooming effect.

//  This is method returns the lastKnownlocation and store it in location object from where then you can retrive latitute and longitude.
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 20.0f));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!