Question

  1. So here's the issue... I have a field where users can type in their address (which will be GeoCoded via Google Maps API).
  2. I have several addresses of widgets in my database (saved as address.. again can easily be geocoded).

What I need is for the user to type in their address and for a list of my widgets to come up based on distance from their address. I have THOUSANDS of addresses for my widgets and users have an infinite number of addresses obviously.

Any ideas?

Thanks.

Was it helpful?

Solution

SELECT latitude, longitude, SQRT( POW( 69.1 * ( latitude - 52.58 ) , 2 ) + 
POW( 69.1 * ( - 1.12 - longitude ) * COS( latitude / 57.3 ) , 2 ) ) AS distance 
FROM location ORDER BY distance

Click Here They provide several ways of calculating the distance - choose what works best for you.

OTHER TIPS

If you are storing the items in a MySQL DB, then here's the basis what you need

You really CAN'T use google to calculate your geo distance filtering. To do that, you would have to send them YOUR data, have them store it, and query it for you. They may offer that service, now, or in the future, but I haven't heard of it.

In order of more legal, more capable, more expensive:

A/ As SINGLE points or locations of interest are input by customers of your site, collect the geo coordiniates. Then use your own search engine and search by distance from a point. MAY be a violation of the agreement with google, but they do mention 'caching' results to take the load off their servers. (The reason is my personal guess.)

B/ Use google to do bulk geocoding, perhaps ONE AT A TIME, to a max of 5000 per day per your site's IP Address last I saw. Not even sure if that is not a violation of the use agreement.

C/ Purchase a contract with a geocoding service, and store what they geocode for you.

D/ Purchase a geocoding library and do your own geocoding.

This blog post, "Calculate Distance using Google Maps API", may be of some assistance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top