簡體   English   中英

latLng返回空對象-Google Maps JavaScript API

[英]latLng returns empty object- Google maps javascript API

我使用帶有javaScript的google map,我的代碼是:

 <script type="text/javascript">
    var map;
    function initialize() {
        var myLatlng = new google.maps.LatLng(-12.043333,-77.028333);
        var myOptions = {
        zoom: 17,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.SATELLITE
      };


      map = new google.maps.Map(document.getElementById('map_canvas'),
          myOptions);
      google.maps.event.addListener(map, "mousedown", function (e) {

                        //lat and lng is available in e object
                        var latLng = e.latLng;
                        console.log(latLng);
                    });
   }

    google.maps.event.addDomListener(window, 'load', initialize);
  </script>` 

e.latLng的結果是一個空對象。 我試圖單擊該事件,但結果為空。 我該怎么辦或更改?

您的代碼工作正常:

點擊地圖,您的坐標會發出alert

在這里檢查

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM