views:

1065

answers:

2

I'm developing a store location application.

Looking up a store, it currently shows the location in googlemaps based on address and zip code.

Now I want to build a function which also shows other shops within 500 meter radius. To do this, I have to do a proximity search / calculation.

My biggest question, is how I should approach this.

I did find this link, which has some example code. But I'm unsure if I can use the code (and which of the codes I should use). Does anyone have better examples?

Also I'm thinking of adding a new table to the database, which stores the geo code for each store. Do I need more fields than 'id', 'latitude' and 'longitude' ?

UPDATE
I just found this link at phpro.org. It looks like it's just what I need! Has anyone used their examples and can comment upon it?

+1  A: 

You cant radius search directly with the google maps API, however, you should know (or can figure them out via geocoding their addresses) the latitude and longitude of each point of interest (POI) you want to include in the search.

After this you can use the Great Circle equation to search for proximity, and it turns out to be very fast. We have implemented this as a stored procedure for the locator service at my work and use it to search through >3500 locations with response times under 0.1 seconds.

NickLarsen
My ISP does not allow stored procedures :(
Steven
You can implement it in code then. The equation is well publicized.
NickLarsen
A: 

Some SQL implementations contain geospatial extensions. In those implementations you can directly write a WHERE clause that filters the results by distance from a specified point.

Check the documentation of your SQL implementation. If it has geospatial POINT type, then it makes sense to enter the coordinates as POINTs rather than a lat/lng pair, and consider using that field as a SPATIAL KEY if you're going to be accessing the table mainly by location.

Mike Williams