我遇到問題。我有一系列經銷商的位置。它被稱爲locations
。每組中的第一項是緯度,每組中的最後一項是經度。我找回了一張正確顯示所有位置的地圖,只是它放大了其中一個位置。它必須是一些界限,但我不知道是什麼。有人可以幫忙嗎?謝謝。GoogleMaps:地圖未擴展邊界以查看所有標記
這裏是我的代碼:
var map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker, i;
if (locations.length > 1) {
var bounds = new google.maps.LatLngBounds();
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][0], locations[i][1]),
map: map
});
}
bounds.extend(marker.getPosition());
map.fitBounds(bounds);
這樣做。謝謝,Heitor。 – sehummel
不客氣! –