1

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

https://i.stack.imgur.com/jvATG.png

https://i.stack.imgur.com/RPsNx.png

https://i.stack.imgur.com/ImmD8.png

https://i.stack.imgur.com/a930b.png

Rinky Kumari
  • 49
  • 1
  • 7
  • 1
    put your complete code with all the 30 markers on map – Silvans Solanki Mar 14 '16 at 08:30
  • @SilvansSolanki Maybe you can re visit this thread again. I have edited the question so that the codes may be displayed. Thanks! –  Mar 14 '16 at 08:38
  • @RinkyKumari Please do preview first your question to avoid any lacking information next time :) Thanks :) –  Mar 14 '16 at 08:39

1 Answers1

0

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 = builder.build();

  • 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.

Community
  • 1
  • 1
ELITE
  • 5,815
  • 3
  • 19
  • 29