How to find closest marker leaflet.js(如何找到最近的标记leaflet.js)
问题描述
我想知道是否真的有某种方法可以使用 Leaflet.js 在我的位置附近找到标记.我想到的第一个想法是存储我的位置的 lat 和 lng,然后遍历一组 lat 和 lng 标记,将它们放在一个数组中,然后对该数组进行排序.我不确定这是否是一个不错的选择,因为如果您在地图上有一百万个标记需要一段时间.
I was wondering if there is actually some way to find markers near my position using leaflet.js. The first think to come to my head is to store lat and lng of my position and then iterate over an array of lat and lng markers placing them in an array an then sort that array. I am not sure if this is a good option because if you have a million markers in the map is going to take a while.
伪代码
var myLatLng = [34,56];
var markers = [[20,30],[10,20],[12,-100],[54,90],[-10, -20],[20,20]];
var closests = [];
function findNearestMarker (myPosition, nearestMarkers){
for(var i = 0; i < nearestMarkers.length){
if((nearestMarkers[i][0] - myPosition[0]) < 100 && (nearestMarkers[i][1] - myPosition[1]) < 100 ){
closests.push(nearestMarkers[i])
}
}
}
我实际上是从地图开始,不知道这么多方法,我也想在这个项目中使用开放的街道地图,但是,如果有人知道并使用谷歌地图或其他服务,我将受到欢迎.
I am actually starting with maps and dont know so many approaches, I will also like to use open street maps for this project, but, if someone know and aproach using google maps or another services it will be welcomed.
推荐答案
试试leaflet-knn,它进行最近邻查找:给定一个点和一堆其他点,它会找到最近的邻居(正如它在锡上所说的那样)
Try leaflet-knn, which does nearest-neighbor lookups: given a point and a bunch of other points, it finds the nearest neighbors (as it says on the tin)
这篇关于如何找到最近的标记leaflet.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何找到最近的标记leaflet.js


- addEventListener 在 IE 11 中不起作用 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01