Hi I wanted to know how I can slowly zoom in on a marker in a map activity in android. Currently my app just opens zoomed in on the marker. I would like it to zoom in slowly when the app is opened.
This is my current code
LatLng mark = new LatLng(21.197384, 6.369441);
mMap.addMarker(new MarkerOptions().position(mark).title("Marker for Mark"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(mark));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
Use mMap.animateCamera
instead of mMap.moveCamera
Also, you can control the duration of the movement using
animateCamera (CameraUpdate update, int durationMs, GoogleMap.CancelableCallback callback)
In your example, change
mMap.moveCamera(CameraUpdateFactory.newLatLng(mark));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
for
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
or, if you want the movement to last 200ms:
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel), 200, null);
Try mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
instead of
mMap.moveCamera(CameraUpdateFactory.newLatLng(mark));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
In this way you can achieve this --
CameraUpdate center= CameraUpdateFactory.newLatLng(new LatLng(latitude_origin, longitude_origin));
CameraUpdate zoom = CameraUpdateFactory.newLatLngZoom(new LatLng(latitude_origin, longitude_origin),3);
googleMap.animateCamera(center);
googleMap.animateCamera(zoom);
Hope this helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.