在传单中拖动事件之后如何获得latlng? [英] How do I get the latlng after the dragend event in leaflet?
本文介绍了在传单中拖动事件之后如何获得latlng?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试更新标记移动后的lat / lng值。提供的示例使用弹出窗口显示lat / lng。
I'm trying to update the lat/lng value of a marker after it is moved. The example provided uses a popup window to display the lat/lng.
我有一个用于标记的dragend事件侦听器,但是当我提醒e的值时。 latlng它返回未定义。
I have a "dragend" event listener for the marker, but when I alert the value of e.latlng it returns undefined.
javascript:
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 © <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。
使用控制台。
latlng value is not in e.latlng but in e.target._latlng . Use console.
这篇关于在传单中拖动事件之后如何获得latlng?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文