in my web app I've got a google map used to display some locations on it. Each of these locations is stored in a db and shown on the map. I need to set the map zoom level so that all the markers are included in the area shown by the map. Thanks for your help.
Asked
Active
Viewed 1,224 times
2 Answers
2
You need to create an instance of LatLngBounds class and then as you add each location/marker to your map you use the extend(point:LatLng)
method to extend the bound by the markers LatLng coordinate. When you're done adding markers and extending the LatLngBounds you use the Map class methods fitBounds(bounds:LatLngBounds)
or panToBounds(latLngBounds:LatLngBounds)
to zoom and move the viewport to fit the bound.
Daniel Vassallo provides a nice code example of all of this at https://stackoverflow.com/a/3521067/881551

Community
- 1
- 1

Anthony Hatzopoulos
- 10,437
- 2
- 40
- 57
1
The zoom level range from 0 to 21 For your case you probably want to set the value to lower as possible probably about 8 or 9. You may see below example here: where it display 10 locations together into one google map.

cmsonnet
- 45
- 2