Google Map get 10 closest Points of all Markers on a Map

后端 未结 2 1191
旧巷少年郎
旧巷少年郎 2020-12-17 02:05

I try to get the 10 closest Markers from the center of the google map and sort them based of the center by distance in Javascript. So lets say i have 100 Markers in a Javasc

2条回答
  •  不思量自难忘°
    2020-12-17 02:10

    Whatever happens You need to calculate all distances. You can do it yourself with simple equations or use Google's geometry library: http://code.google.com/intl/pl-PL/apis/maps/documentation/javascript/geometry.html and its function: computeDistanceBetween(). Then store distance in custom marker property like e.g:

    marker.distance = google.maps.geometry.spherical.computeDistanceBetween(marker.position, center.position);
    

    and sort it anyway you want. Hope it helps.

提交回复
热议问题