android Zoom-to-Fit All Markers on Google Map v2 [closed]
Asked Answered
E

1

7

How to zoom in/out the map view such a way that it cover all markers?

i am reviewing sample code of gmap V2 given in sdk. It lays on sdk\extras\google\google_play_services\samples\maps.

Thanks in advance.

Exosmosis answered 7/5, 2013 at 8:43 Comment(0)
P
63

Try using LatLngBounds :

LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(Latlng1);
builder.include(Latlng2);
LatLngBounds bounds = builder.build();
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 20));
Pronucleus answered 7/5, 2013 at 8:47 Comment(13)
I am using the same but it is not covering all markers. It hangs som where between.Exosmosis
what do you mean by: "It hangs som where between"? are you including all Latlng point in the builder?Pronucleus
Yes I am including the same way you have told, even it finds between latlong but not zoomed view is seen....Exosmosis
did you get any answer? it is also not working for me tooTriphylite
Not working for me too..Drakensberg
this solutions is working for me just fine...Pronucleus
@DanielG.R. well it worked well for me. Maybe there were changes in the API by Google. Please check the documentation.Pronucleus
It works, you are right, excuse me :)Picky
It didn´t let me remove it until x hours, done ;)Picky
Thanks for removing it.Pronucleus
I am using the same but it is not covering all markers.Floret
Worked for me also :) THanksTerritory
// Kotlin Code if someone needs: var allMarkers: MutableList<Marker> = mutableListOf() allMarkers.add(marker1) allMarkers.add(marker2) val builder = LatLngBounds.Builder() allMarkers.forEach { // All marker array builder.include(it.position) } val bounds = builder.build() mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100))Cawley

© 2022 - 2024 — McMap. All rights reserved.