android - Find items within a certain range of given coordinate -


i have django based web app stores locations.

i have android mobile app pulls locations web app , saves locations web app. locations returned me load on mapoverlay in app.

i send current coordinates , return list of locations within range. example send location , items within radius of 2km. (similar how google places api works, searching data).

it best send location coordinates , logic in python django app, return list of correct locations , display places on map.

i don't know begin doing this. how can filter out stored locations within radius(km) based off given set of coordinates?

haversine equation answer question. difficult decrypt here provide simple explanation:

to put simply:

here's sample/example sql statement find closest 20 locations within radius of 25 miles 37, -122 coordinate. calculates distance based on latitude/longitude of row , target latitude/longitude (given lat/lng in equation below), , asks rows distance value less 25, orders whole query distance, , limits 20 results. search kilometers instead of miles, replace 3959 6371.

select id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) distance markers having distance < 25 order distance limit 0 , 20; 

you can convert sql desire. mean principle remains same.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -