我是JS的初学者。 我有这个对象:
var lc = L.control.locate().addTo(map);
console.log(lc);
我如何需要2个变量:long和lat具有该对象的值(纬度和经度)。如何获得它们?
答案 0 :(得分:0)
lc ['_ event'] ['latitude']将带您进入纬度和
lc ['_ event'] ['longitude']将带您进入经度
为将来参考,建议您搜索: JavaScript对象变量
答案 1 :(得分:0)
如果您使用的是Leaflet.Locate plugin,则只需参考其文档mentions,即可使用Leaflet内置位置事件:
您可以利用本地Leaflet事件
onlocationfound
和onlocationerror
来处理地理定位成功或产生错误的时间。您可以在Leaflet documentation中找到有关这些事件的更多信息。
链接的教程为您提供了一个代码片段,该代码片段如何使用位置找到事件获取坐标:
function onLocationFound(e) {
var radius = e.accuracy; // Note: accuracy is already a radius
L.marker(e.latlng).addTo(map)
.bindPopup("You are within " + radius + " meters from this point").openPopup();
L.circle(e.latlng, radius).addTo(map);
}
map.on('locationfound', onLocationFound);