使用标记的谷歌地图 setCenter 无法正常工作,因为它在左上角而不是中心显示市场。以下是我使用的代码:
<body id="ViewMapScreen">
<div id="map" style="width: 600px; height: 349px;"></div>
<script type="text/javascript">
var address = 'Pune, Maharastra, India';
var map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoom: 8
});
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
'address': address
},
function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
new google.maps.Marker({
position: results[0].geometry.location,
map: map
});
map.setCenter(results[0].geometry.location);
}
});
</script>
</body>