传单:如果选项 "watch" 设置为 "true",则后续 map.locate() 超时
Leaflet: Subsequent map.locate() times out if option "watch" is set to "true"
我正在努力解决 leaflet 的 map.locate() 首先会正确引发 "locationfound" 事件的问题,但无论我做什么,每个后续调用都会 timeout/freeze .
如果 "watch" 设置为 false,调用 "map.locate(options)" 将正常工作。
重现步骤:
- 打开上面的link,
- 单击一次地理定位按钮并等待,
- 地图将缩放到地理位置,
- 平移地图,
- 再次单击地理定位按钮,
- 看着它失败(在控制台中)
有什么解决办法吗?
function geolocateMe() {
if (!registered) {
map.on("locationfound", cb);
map.on("locationerror", eb);
registered = true;
}
map.locate({
watch: true,
setView: true
});
}
在这里看到这个 plunker Leaflet locate issue
好的,需要在此处正确阅读地理位置 API Geolocation API- watchPosition()
因为超时和 maximumAge 是至关重要的。基本上,这就是我不喜欢的地方,如果您提供超时和 maximumAge,那么如果位置没有在超时值内更新,则会抛出 "locationerror" 并出现超时错误。我认为这是误导,应该有 "no-update-within" 更容易理解的事件。
基本上如果你不提供超时,那么每个位置请求都会查看缓存的位置,如果这比上次更新后的 maximumAge 旧,它会立即触发从设备获取新的位置.
var geo_options = {
enableHighAccuracy: true,
maximumAge: 60000
//timeout : 1000
};
在另一个使用基本地理定位的 plunker 中尝试一下 api -> enter link description here
希望对您有所帮助。我只是很困惑,为什么我会收到所有超时消息而没有位置信息。现在我明白了。
我正在努力解决 leaflet 的 map.locate() 首先会正确引发 "locationfound" 事件的问题,但无论我做什么,每个后续调用都会 timeout/freeze .
如果 "watch" 设置为 false,调用 "map.locate(options)" 将正常工作。
重现步骤:
- 打开上面的link,
- 单击一次地理定位按钮并等待,
- 地图将缩放到地理位置,
- 平移地图,
- 再次单击地理定位按钮,
- 看着它失败(在控制台中)
有什么解决办法吗?
function geolocateMe() {
if (!registered) {
map.on("locationfound", cb);
map.on("locationerror", eb);
registered = true;
}
map.locate({
watch: true,
setView: true
});
}
在这里看到这个 plunker Leaflet locate issue
好的,需要在此处正确阅读地理位置 API Geolocation API- watchPosition()
因为超时和 maximumAge 是至关重要的。基本上,这就是我不喜欢的地方,如果您提供超时和 maximumAge,那么如果位置没有在超时值内更新,则会抛出 "locationerror" 并出现超时错误。我认为这是误导,应该有 "no-update-within" 更容易理解的事件。
基本上如果你不提供超时,那么每个位置请求都会查看缓存的位置,如果这比上次更新后的 maximumAge 旧,它会立即触发从设备获取新的位置.
var geo_options = {
enableHighAccuracy: true,
maximumAge: 60000
//timeout : 1000
};
在另一个使用基本地理定位的 plunker 中尝试一下 api -> enter link description here
希望对您有所帮助。我只是很困惑,为什么我会收到所有超时消息而没有位置信息。现在我明白了。