如何找到最接近的标记leaflet.js [英] How to find closest marker leaflet.js

查看:716
本文介绍了如何找到最接近的标记leaflet.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否确实是有一些方法来找到使用leaflet.js靠近我的位置标记。第一个想到要来我的头是存储纬度和经度我的立场,然后遍历的纬度和经度标志放置在数组中的排序,然后该数组的数组。我不知道这是否是一个很好的选择,因为如果你在地图上百万的标记是要需要一段时间。

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.

伪code

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.

推荐答案

尝试传单-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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆