javascript 在传单中找到保存标记的纬度和经度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16036824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 03:00:06  来源:igfitidea点击:

find latitude & longitude of saved marker in leaflet

javascriptleafletmarkers

提问by vaibhav shah

I have circle marker

我有圆圈标记

var myMarker = L.circleMarker(stuSplit, 
    { title: 'unselected' })
        .bindLabel("Name: " + students[i][j][0] 
                   + " ReachTime: " + students[i][j][2]);

Now I want to find latitude & Longitude this myMarker.

现在我想找到这个 myMarker 的纬度和经度。

I was trying myMarker.getLatLng()but it is not working.

我正在尝试,myMarker.getLatLng()但它不起作用。

回答by flup

The problem does not lie in getLatLng(). This works fine:

问题不在于 getLatLng()。这工作正常:

var map = L.map('map').setView([55.4411764, 11.7928708], 13);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

var stuSplit = L.latLng(55.4411764, 11.7928708);
var myMarker = L.circleMarker(stuSplit, 
    { title: 'unselected' })
        .addTo(map);
alert(myMarker.getLatLng());

See a working example here:

在此处查看工作示例:

http://jsfiddle.net/pX2xn/2/

http://jsfiddle.net/pX2xn/2/

回答by Injection

So you can

所以你可以

$("#One").click(function(){
    var curPos = myMarker.getLatLng();
    alert(curPos.lng + " : " + curPos.lat);
});

this in more detail.

这更详细。

See a working example here.

请参阅此处的工作示例。