Leaflet - 可拖动的标记和坐标以字段形式显示

Leaflet - draggable marker and coordinates display in a field form(Leaflet - 可拖动的标记和坐标以字段形式显示)
本文介绍了Leaflet - 可拖动的标记和坐标以字段形式显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!


我必须做一个可拖动的标记,它的坐标应该显示在字段中.它将成为 PHP 中联系表单的一部分.我创建了一个可拖动的标记,请帮助我现在该怎么做.

I have to do a draggable marker and its coordinates should be displayed in fields. It will be a part of a contact form in PHP. I created a draggable marker, help me what to do now.

var marker = L.marker(new L.LatLng(53.471, 18.744), {
draggable: true


这是 Google Maps API 中的示例,我需要在 Leaflet 中使用相同的示例.

Here is example in Google Maps API, I need the same in Leaflet.



You should use the dragend event of L.Marker, so you known dragging has ended, then get the coordinates of the marker by using the getLatLng method of L.Marker. When you've fetched those you can assign them to the values of your text inputs.

marker.on('dragend', function (e) {
    document.getElementById('latitude').value = marker.getLatLng().lat;
    document.getElementById('longitude').value = marker.getLatLng().lng;

Plunker 上的工作示例:http://plnkr.co/edit/iyMhaoAyllr2uNSOHhS9?p=preview

Working example on Plunker: http://plnkr.co/edit/iyMhaoAyllr2uNSOHhS9?p=preview

这篇关于Leaflet - 可拖动的标记和坐标以字段形式显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



How do I can get a text of all the cells of the table using testcafe(如何使用 testcafe 获取表格中所有单元格的文本)
node_modules is not recognized as an internal or external command(node_modules 未被识别为内部或外部命令)
How can I create conditional test cases using Protractor?(如何使用 Protractor 创建条件测试用例?)
PhantomJS and clicking a form button(PhantomJS 并单击表单按钮)
Clicking #39;OK#39; on alert or confirm dialog through jquery/javascript?(在警报上单击“确定或通过 jquery/javascript 确认对话框?)
QunitJS-Tests don#39;t start: PhantomJS timed out, possibly due to a missing QUnit start() call(QunitJS-Tests 不启动:PhantomJS 超时,可能是由于缺少 QUnit start() 调用)