我有一些我要检索并希望将地图居中的标记。是的,我已经阅读了所有其他答案,但它似乎对我不起作用: Google Map API v3 — set bounds and center
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);
}
}