Latitude / Longitude Sort List

So, I have a google map on my site. I need the user to be able to centralize the map somewhere, and then I want on my server side to be able to sort the list of objects (each of which has the lat and long property) based on the visible part of the map at the front end. Does this make sense? Think about how Yelp.com sorts restaurants based on a map, users can zoom in / out.

So, first the list will get rid of any objects that are not in the map area, based on their lat / long properties, and then sort the remaining ones, based on which they are closest to the center of the map.

To do this, what would I need to pass to the server from the external interface, and as soon as it appears on the server, how would I do this sorting?

+4
source share
3 answers

calculate the great_circle_distance value, then sort by the smallest number.

+4
source

Use the Haversin Formula to calculate the long distance of a circle:

http://en.wikipedia.org/wiki/Haversine_formula

Then sort first the shortest distance (= closest).

+1
source

From the sound of this, you may want to save the tiles or whatever you extract in something like a quadrant. Then you can transfer the coordinates to the server, the server can extract the objects visible in this aperture, sort them, and then send them back.

+1
source

Source: https://habr.com/ru/post/1346792/


All Articles