Getting particular location of google map in center in android studio

I used this code to get particular location in center.

mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(33.7167, 73.0667), 4))

It worked somehow but after putting 30 no of markers simultaneously. I didn't get location in center.

this is my snippet of code


You can update camera to the center of bounds of markers. For that -

  • Create LatLngBounds.Builder object and add all the markers in it.

    LatLngBounds.Builder builder = new LatLngBounds.Builder();

  • While adding marker store it to variable like

    Marker marker1 = mMap.addMarker(....); Marker marker2 = mMap.addMarker(....);

  • Then add all markers in it using

    builder.include(marker1.getPosition()); builder.include(marker2.getPosition());

  • Then build LatLngBounds

    LatLngBounds bounds =;

  • Then create CameraUpdate and animate camera to relative position

    int padding = 0; // offset from edges of the map in pixels CameraUpdate camUpdate = CameraUpdateFactory.newLatLngBounds(bounds, padding); mMap.animateCamera(camUpdate);

And done.

Refer this answer for more details.

Hope it'll work.

Need Your Help

Is there a simple way I can tokenize a string without a full-blown lexer?

javascript computer-science tokenize lexer shunting-yard

I'm looking to implement the Shunting-yard Algorithm, but I need some help figuring out what the best way to split up a string into its tokens is.

Node.js proper callback error handle

javascript node.js callback

Lets take a look at the following code: