简体   繁体   English

如何使用OSM在我的当前位置放置标记?

[英]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.

相关问题 如何在Angularjs中使用ngMap访问地图标记的当前位置(纬度,经度)? - How do I access the current location (lat, lng) of a map marker using ngMap in Angularjs? 如何在反应原生地图中拖动我当前的位置标记? - How to drag my current location marker in react native maps? 如何在我当前的位置html5上居中放置地图 - how do I center a map on my current location html5 如何使用 react-native-maps 和 Marker Library 将标记位置设置为用户当前位置 onInit - How to set Marker location to users current location onInit, using react-native-maps and Marker Library Google Maps API:在当前地图位置放置标记 - Google Maps API: Place marker at current map location 在OSM地图中操作/选择一个位置并显示标记 - Action/Select a Location in OSM Map and Show Marker 如何在D3中按顺序刻度将自制的三角形放置在特定位置上? - How do I place my self-made triangle on a specific location with my ordinal scale in D3? 如何使用OSM在openstreetmap中获取标记或任何图标 - how to get marker or any icon in openstreetmap using OSM 使用watchPosition仅显示当前位置标记 - Show only the current location marker using watchPosition 如何在php中使用当前位置查找最近的位置图像? - how can find nearest place image using current location in php?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM