I use the following code to set markers on my map:
var latLngs = []
$.each(locations.markers, function(i, m){
var myLatLng = new google.maps.LatLng(m.latitude, m.longitude);
latLngs[i] = myLatLng
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
shadow: shadow,
icon: image,
shape: shape,
title: m.city,
zIndex: i
});
})
The markers show up on my map. Now I would like to center & zoom the map on these markers. How can I accomplish this?
I have tried:
map.fitBounds(getBoundsForLatLngs(latLngs));
The console.log of latLngs gives out:
[(46.793182, 7.146903) { b=46.793182, more...}, (46.8077779, 7.1709386) { b=46.8077779, more...}]
But it doesn't seem to work, and I get no error in the console. What am I doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…