javascript - How to find closest marker leaflet.js -
i wondering if there way find markers near position using leaflet.js. first think come head store lat , lng of position , iterate on array of lat , lng markers placing them in array sort array. not sure if option because if have million markers in map going take while.
pseudo 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 = 0; < nearestmarkers.length){ if((nearestmarkers[i][0] - myposition[0]) < 100 && (nearestmarkers[i][1] - myposition[1]) < 100 ){ closests.push(nearestmarkers[i]) } } } i starting maps , dont know many approaches, use open street maps project, but, if know , aproach using google maps or services welcomed.
try leaflet-knn, nearest-neighbor lookups: given point , bunch of other points, finds nearest neighbors (as says on tin)
Comments
Post a Comment