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
  • 5,996
  • 16
  • 49
  • 56
LNyarla
  • 325
  • 1
  • 7
  • 20

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,259
  • 2
  • 37
  • 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