Ahmad Gulzar
Ahmad Gulzar

Reputation: 363

Searching record within latitude and longitude range

hi i am using this map

https://google-developers.appspot.com/maps/articles/mvcfun/step6

i can get the latitude and longitude of the required location also i can get the distance (radius). so i have a database in which my each record have latitude and longitude. i want to search the record within the range selected on the map. how the sql query will work ?

for better explanation my each record have a latitude and longitude. user will select the map and i want to search the record within selected range.

Upvotes: 2

Views: 1766

Answers (1)

ChrisSwires
ChrisSwires

Reputation: 2723

The way I have always done this is to use the maps api to draw a circle with the required radius, find the lat long bounds of this circle and then query the database:

SELECT * FROM yourtable WHERE lat BETWEEN a AND c AND lng between b AND  d

Where a and b are you top left coordinates and c and d are your bottom right. (more information available here).

Now that you have all objects within your bounding box you will need to pass them back to your front-end and determine whether or not they are within your radius. See this answer for more information.

Upvotes: 2

Related Questions