[英]Google maps setCenter using marker is not working properly as its is showing the market at left-top instead of center
Google使用標記在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>
更改div的寬度和高度,即可正常工作。
<div id="map" style="width: 1270px; height: 850px;"></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.