javascript - latLng 返回空对象 - Google map javascript API

标签 javascript google-maps

我使用带有 javaScript 的谷歌地图,我的代码是:

 <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 的结果是一个空对象。 我尝试单击该事件,但结果为空。 我应该做什么或改变什么?

最佳答案

您的代码运行良好:

点击 map ,您的坐标将出现警报

请查看here

关于javascript - latLng 返回空对象 - Google map javascript API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46112449/

相关文章:

javascript - Three.js - Torus 不绕 0z 轴旋转

javascript - 无限滚动导致快速滚动时跳转到屏幕顶部

google-maps - Google maps API robots.txt 文件拦截抓取

objective-c - -[GMSMapView animateToCameraPosition :]: unrecognized selector sent to instance

javascript - Mousedown 事件不会在 select2 下拉列表中触发

javascript - 什么情况下函数不能访问全局变量?为什么?

java - Spring-Maven : Unable to load Javascript file

javascript - 迭代响应数据以创建谷歌地图对象

android - 在 Android 中将 map 标记居中

google-maps - 标记管理器无法在Maps API 3.10中使用