AndroidDev AndroidDev - 3 months ago 14
Android Question

Center a map marker in Android

I use the following code to display a single marker at a zoom level but it doesn't center tha marker on the map. Only one marker will ever be shown:

LatLng latLng = new LatLng(Latitude, Longitude);
cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 11.0f);


This code will center it but it doesn't provide any zoom:

LatLngBounds bounds = latLngBuilder.build();
cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, 30);


I need to center AND zoom.

Answer

The correct value for zoom is between 2.0 and 22.00.

After this you've to add this line

GoogleMap mMap;
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(latlng, 10));

About zoom you can read this from documentation 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.

You can check this on http://developer.android.com/reference/com/google/android/gms/maps/CameraUpdateFactory.html