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

后端 未结 2 1188
旧巷少年郎
旧巷少年郎 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.

    0 讨论(0)
  • 2020-12-17 02:28
    1. Sort the array by proximity to your map's centre point. Use sort().
    2. Slice the first 10 with slice().
    3. Plot these on the map.
    0 讨论(0)
提交回复
热议问题