我有几个标记,我检索并希望将地图居中。 是的,我看过所有其他的答案,但它似乎并没有为我工作: Google Map API v3 — set bounds and center谷歌地图API v3 - fitBounds中心只有一个标记
JS:
geocoder.geocode({'address': loc}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var markerBounds = new google.maps.LatLngBounds();
var coordinate = results[0].geometry.location;
var icon = new google.maps.MarkerImage("images/icon-"+type+".png", new google.maps.Size(37, 44));
//create the marker
var marker = new google.maps.Marker({
map: map,
position: coordinate,
visible: true,
id: type,
shadow: shadow,
icon: icon
});
markerBounds.extend(coordinate);
map.fitBounds(markerBounds);
}
}
yesssssssssir +1 –
是的,我认为是很好,我试图确定有markerBounds(和所有其他可能的地方,你可以把它)。 但我再次尝试了你的方式,但仍然只是像你说的最后一个中心.. – meneerfab
嗯,这很奇怪..如果它在一个地方,它只会执行一次它应该工作。您发布的代码上面是什么? – iwiznia