我有以下代码:
<?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>
出于某种原因,当地图加载时,缩放级别已满,因此它会直接放大到标记中。我尝试在初始化部分调整缩放级别,但我没有高兴。我的猜测是,它与标记边界有关。任何人都知道如何调整缩放以使其不会完全缩放到标记上?