[英]How do I place a marker on my current location using OSM?
I'm pretty new to Javascript and OSM. 我是Java和OSM的新手。 I was wondering how to retrieve coordinates from map.locate().
我想知道如何从map.locate()中检索坐标。 My current code looks like this:
我当前的代码如下所示:
function getLocation(){ map.locate({setView: true, enableHighAccuracy: true}) .on('location found', function(e){ var marker = new L.marker(e.latlng); marker.addTo(map); });
When I run this code, it gets my current location but the marker won't show. 当我运行此代码时,它将获取我的当前位置,但标记不会显示。
Typo: event name is "locationfound"
(no whitespace) 错字:事件名称为
"locationfound"
(无空格)
Demo: https://jsfiddle.net/3v7hd2vx/93/ 演示: https : //jsfiddle.net/3v7hd2vx/93/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.