我在一个跨平台的移动应用程序中使用Leaflet。
我希望用户能够实时看到他/她在地图上的移动。
我还希望将它们的经度和纬度分别保存为全局变量,以便稍后进行计算时需要此信息。
以下是我到目前为止所掌握的:
map.locate({
watchPosition:true,
maxZoom:16
});
function onLocationFound(e)
{
var radius = e.accuracy / 2;
L.circle(e.latlng, radius,
{
color: 'red',
fillColor: '#f03',
fillOpacity: 0.5,
radius: 400
}).addTo(map);
}
map.on('locationfound', onLocationFound);
我相信"watchPosition:true“可以让地图保持对用户的监视。
我只是想不出如何提取经度和纬度信息。
提前感谢
发布于 2018-07-09 23:38:23
Leaflet map.locate
选项仅为watch
如果为
true
,则使用W3CwatchPosition
方法开始连续监视位置更改(而不是一次检测)。
发布于 2018-08-02 01:56:32
function onLocationFound(e)
{
var radius = e.accuracy / 2;
userLat = e.latlng.lat;
userLng = e.latlng.lng;
movingCircle.setLatLng(e.latlng);
movingCircle.redraw();
}
var userLocation = map.locate
({
watch:true,
maxZoom:16,
enableHighAccuracy: true
});
var userLat;
var userLng;
enter code here
var movingCircle = L.circle([0,0], 20,
{color: 'red',
fillColor: '#f03',
fillOpacity: 0.5,
draggable: true }).addTo(map);
https://stackoverflow.com/questions/51248286
复制相似问题