gpt4 book ai didi

event-handling - 在传单中的dragend事件之后如何获取latlng?

转载 作者:行者123 更新时间:2023-12-03 12:28:41 24 4
gpt4 key购买 nike

我正在尝试移动标记后更新其经度/经度值。提供的示例使用 pop 窗口显示经度/纬度。

我有一个标记的“dragend”事件侦听器,但是当我警告e.latlng的值时,它返回未定义。

javascript:

function markerDrag(e){
alert("You dragged to: " + e.latlng);
}

function initialize() {
// Initialize the map
var map = L.map('map').setView([38.487, -75.641], 8);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
maxZoom: 18
}).addTo(map);

// Event Handlers
map.on('click', function(e){
var marker = new L.Marker(e.latlng, {draggable:true});
marker.bindPopup("<strong>"+e.latlng+"</strong>").addTo(map);

marker.on('dragend', markerDrag);
});
}


$(document).ready(initialize());

http://jsfiddle.net/rhewitt/Msrpq/4/

最佳答案

latlng值不在e.latlng中,而在e.target._latlng中。
使用控制台。

关于event-handling - 在传单中的dragend事件之后如何获取latlng?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18382945/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com