0

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.

Kara
  • 6,115
  • 16
  • 50
  • 57
LNyarla
  • 454
  • 1
  • 8
  • 23

2 Answers2

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.

http://www.webkeet.com/webtutorials/tabid/78/id/53/using-reverse-geocoding-latitude-and-longitude-and-address-geocoding-to-display-google-map.aspx

cmsonnet
  • 45
  • 2