简体   繁体   English

Google使用标记标记setCenter不能正常工作,因为它在左上角而不是中心显示市场

[英]Google maps setCenter using marker is not working properly as its is showing the market at left-top instead of center

Google maps setCenter using marker is not working properly as its is showing the market at left-top instead of center. Google使用标记在setCenter上绘制的地图无法正常运行,因为它在左上角而不是中间显示市场。 Following is the code that i have used : 以下是我使用的代码:

<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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM