【问题标题】:google map marker dragging doesnt work谷歌地图标记拖动不起作用
【发布时间】:2015-03-09 06:34:35
【问题描述】:

拖动标记后无法获取经纬度,请告知我的错误

提前谢谢你

这里的js代码:

<script>
 function initialize_map(lat,lng) {
        $("#request-form").show();
        latitude = parseFloat(lat);
        longitude = parseFloat(lng);
        var myLatlng = new google.maps.LatLng(latitude,longitude);
        var mapOptions = {
          zoom: 14,
          center: myLatlng
        }
        var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

        var marker = new google.maps.Marker({
            position: myLatlng,
            map: map,
            title: 'Hello World!',
            draggable: true,
        });

         google.maps.event.addListener(marker, 'dragend', function (marker) {
          var latLng = marker.latLng;
    document.getElementById("latitude").value = latLng.lat()
    document.getElementById("longitude").value = latLng.lng();
});

      }

【问题讨论】:

标签: javascript google-maps draggable


【解决方案1】:

不是将标记传递给 dragend 函数处理程序,而是传递事件。

google.maps.event.addListener(marker, 'dragend', function (event) { 
...
}

【讨论】:

    猜你喜欢
    • 2016-04-10
    • 1970-01-01
    • 2014-04-23
    • 2023-03-21
    • 2012-08-07
    • 2011-08-07
    • 2016-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多