Google Maps v2 - set both my location and zoom in
You cannot animate two things (like zoom in and go to my location) in one google map?
From a coding standpoint, you would do them sequentially:
CameraUpdate center=
CameraUpdateFactory.newLatLng(new LatLng(40.76793169992044,
-73.98180484771729));
CameraUpdate zoom=CameraUpdateFactory.zoomTo(15);
map.moveCamera(center);
map.animateCamera(zoom);
Here, I move the camera first, then animate the camera, though both could be animateCamera()
calls. Whether GoogleMap
consolidates these into a single event, I can't say, as it goes by too fast. :-)
Here is the sample project from which I pulled the above code.
Sorry, this answer is flawed. See Rob's answer for a way to truly do this in one shot, by creating a CameraPosition
and then creating a CameraUpdate
from that CameraPosition
.
It's possible to change location, zoom, bearing and tilt all in one go. It's also possible to set the duration on the animateCamera()
call.
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(MOUNTAIN_VIEW) // Sets the center of the map to Mountain View
.zoom(17) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
Have a look at the docs here:
https://developers.google.com/maps/documentation/android/views?hl=en-US#moving_the_camera
this is simple solution for your question
LatLng coordinate = new LatLng(lat, lng);
CameraUpdate yourLocation = CameraUpdateFactory.newLatLngZoom(coordinate, 5);
map.animateCamera(yourLocation);