0
我有以下代碼:谷歌地圖API的初始變焦錯誤
<?php if($_GET['postcode']){ ?>
//alert(<?php echo $_GET['postcode'];?>)
<?php }?>
function initialize() {
var mapOptions = {
zoom: 6,
center: new google.maps.LatLng("<?php echo $_GET['postcode'];?>"),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map_canvas'),mapOptions);
map.setTilt(45);
var addressArray = new Array("<?php echo $_GET['postcode'];?>");
var geocoder = new google.maps.Geocoder();
var markerBounds = new google.maps.LatLngBounds();
for (var i = 0; i < addressArray.length; i++) {
geocoder.geocode({ 'address': addressArray[i]}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h4 id="firstHeading" class="firstHeading">HELLO</h4>'+
'<div id="bodyContent">'+
'<p><b>Hello!!</b>' + <?php echo $_GET["order_id"];?> + '</p>'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
map: map,
title:"Order Number",
position: results[0].geometry.location
});
markerBounds.extend(results[0].geometry.location);
map.fitBounds(markerBounds);
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
}
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>
出於某種原因,當地圖加載起來,縮放級別是滿的,所以它的縮放到合適的標記。我試着調整初始化部分的縮放級別,但我沒有喜悅。我的猜測是,它與標記邊界有關。任何人都知道如何調整縮放以使其不能完全放大標記?