VolkNet
05-23-2006, 02:48 PM
I have a list of about 20 gallery locations (for an artist).
I want people to be able to input their address and then the script be able to tell them the nearest location.
Anyone know of a script like this? (kinda like a store locator type script)
JustinSmall
05-23-2006, 02:49 PM
I'll do some looking round for ya.
Vdevelopers
05-23-2006, 04:14 PM
http://www.geocoder.us/
It's a Perl freely available library although it requires that you have the massive database.
What you need to do is use this Geocoder to find their latitude and longitude and then run an SQL query against a list of gallery locations (which has their respective latitude and longitude). The geocoder is a little bit of a pain to set up so if you want to use one, let me know, I have one running on my server and I could let you query it.
Your SQL query, once you have the latitude/longitude of the user and the locations, would look like this:
SELECT street, city, zipcode, SQRT( POW(69.1 * (latitude - $latitude), 2) + POW(69.1 * ($longitude - longitude) * COS(latitude / 57.3), 2 ) ) AS distance FROM locations ORDER BY distance ASC
Where $latitude is the user's latitude and $longitude is the user's longitude.