-1
我有一個自定義谷歌地圖here,它有幾個固定的位置。自定義谷歌地圖不縮小
出於某種原因改變zoom
值時,地圖上沒有縮小:
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: new google.maps.LatLng(59.265881,20.515594),
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
streetViewControl: false,
panControl: false,
zoomControlOptions: {
position: google.maps.ControlPosition.LEFT_BOTTOM
}
});
任何想法可能會造成的呢?
休息的腳本:
var locations = [
['html', coordinates],
['html', coordinates],
['html', coordinates],
['html', coordinates],
['html', coordinates],
];
// Setup the different icons and shadows
var iconURLPrefix = 'http://www.bridgingthebaltic.org/wp-content/themes/dante-child/images/';
var icons = [
iconURLPrefix + 'map_icon.png',
iconURLPrefix + 'map_icon.png',
iconURLPrefix + 'map_icon.png',
iconURLPrefix + 'map_icon.png',
iconURLPrefix + 'map_icon.png',
iconURLPrefix + 'map_icon.png',
]
var icons_length = icons.length;
var shadow = {
anchor: new google.maps.Point(15,33),
url: iconURLPrefix + 'map_icon.png'
};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: new google.maps.LatLng(59.265881,20.515594),
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
streetViewControl: false,
panControl: false,
zoomControlOptions: {
position: google.maps.ControlPosition.LEFT_BOTTOM
}
});
var infowindow = new google.maps.InfoWindow({
maxWidth: 450
});
var marker;
var markers = new Array();
var iconCounter = 0;
// Add the markers and infowindows to the map
for (var i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
icon : icons[iconCounter],
shadow: shadow
});
markers.push(marker);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
iconCounter++;
// We only have a limited number of possible icon colors, so we may have to restart the counter
if(iconCounter >= icons_length){
iconCounter = 0;
}
}
function AutoCenter() {
// Create a new viewpoint bound
var bounds = new google.maps.LatLngBounds();
// Go through each...
$.each(markers, function (index, marker) {
bounds.extend(marker.position);
});
// Fit these bounds to the map
map.fitBounds(bounds);
}
AutoCenter();
是的,你說得對。刪除對AutoCenter功能的呼叫解決了我的問題。下一次,我會提醒自己在徵求建議之前先閱讀整個代碼。 :) – Laniakea