5

I am using GMaps.js and I have several points to show, I need to show all and set the zoom to the point, I was watching the documentation and requests an array of google.maps.LatLng type. I have the following code

for (x in geo){
var item  = new google.maps.LatLng(geo[x]["latitud"], geo[x]["longitud"]);
arrayBound.push(item);
}
map = new GMaps({
div: '#divMapa',
lat: latWS,
lng: lngWS,
zoom: 13
});

map.fitBounds(arrayBound);
Jeff
  • 12,147
  • 10
  • 51
  • 87
  • 1
    The solution is map.fitLatLngBounds (arrayBound); The documentation is the fitBounds function but must be fitLatLngBounds and pass as a parameter an array of objects google.maps.LatLng – Enrique Ardavin Dec 13 '13 at 14:28

2 Answers2

13

I didn't find the solution obvious, but, here is an example that works with v0.4.11:

var latlngs = [{lat:"39.158542", lng:"-84.423903"}, {lat:"39.4339357", lng:"-84.9850474"}];
var bounds = [];
for (var i in latlngs) {
  var latlng = new google.maps.LatLng(latlngs[i].lat, latlngs[i].lng);
  bounds.push(latlng);
  map.addMarker({
    lat: latlngs[i].lat,
    lng: latlngs[i].lng
  });
}
map.fitLatLngBounds(bounds);
josephdpurcell
  • 1,157
  • 3
  • 16
  • 34
-1

Rename fitBounds to fitLatLngBounds.

Im0rtality
  • 3,463
  • 3
  • 31
  • 41