这是我用3个引脚/标记来显示地图:谷歌地图API V3:自中心地图多个标记
<script>
function initialize() {
var locations = [
['DESCRIPTION', 41.926979,12.517385, 3],
['DESCRIPTION', 41.914873,12.506486, 2],
['DESCRIPTION', 41.918574,12.507201, 1]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 15,
center: new google.maps.LatLng(41.923, 12.513),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
}
function loadScript() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&' + 'callback=initialize';
document.body.appendChild(script);
}
window.onload = loadScript;
</script>
<div id="map" style="width: 900px; height: 700px;"></div>
我正在寻找的是要避免的方法“手动”找到中心的地图中心:new google.maps.LatLng(41.923,12.513)。有没有办法让地图自动以3个坐标为中心?
的可能的复制[谷歌地图API第3版:我可以fitBounds后setZoom(http://stackoverflow.com/questions/ 2437683/google-maps-api-v3-can-i-setzoom-fit-fit) –