How to use fitBounds of GMaps.js
Asked Answered
R

2

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);
Rosauraroscius answered 12/12, 2013 at 18:31 Comment(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.LatLngRosauraroscius
E
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);
External answered 19/4, 2014 at 21:16 Comment(0)
P
-1

Rename fitBounds to fitLatLngBounds.

Patronizing answered 18/3, 2014 at 16:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.