So, I have a google map on my website. I need the user to be able to center the map somewhere, and then I want on my server side, to be able to sort a list of objects (that each have a lat and long property), based on the visible portion of the map on the front end. Does this make sense? Think the way Yelp.com sorts restaurants based on the map users can zoo开发者_如何学Gom in/out of.
So first the list would get rid of any objects that aren't in the region of the map based on their lat/long properties, and then it would sort the remaining based on which ones are closest to the center of the map.
To do this, what would I have to pass to the server from the front end, and once it's on the server, how would I do this sorting?
calculate the great_circle_distance, then sort by the smallest number.
Use the Haversine Formula to calculate the great circle distance:
http://en.wikipedia.org/wiki/Haversine_formula
Then sort, with the shortest distance (=closest) first.
From the sound of it, you may want to store the tiles or whatever you are retrieving in something like a quadtree. Then you can pass the coordinates to the server, the server can retrieve the objects visible in that aperture for you, sort them, then send them back.
精彩评论