Page 1 of 1

Determining Nearest Coordinates

Posted: Thu Mar 24, 2011 12:42 pm
by JakeJ
I have a table of about 400 different Lat/Long. coordinates. I could probably build my own script but I was hoping maybe someone had something like that built already that they would be willing to share.

The purpose of this script will be to direct a user to a regional page based on their IP location.

Thanks!

Re: Determining Nearest Coordinates

Posted: Thu Mar 24, 2011 3:08 pm
by pickle
Why are you doing this with co-ordinates & not other Geo-ip information? For example, you can use Geo-IP to give one page to everyone in Canada. Another page to everyone in Estonia, etc.

Are these 400 co-ordinates spaced out everywhere on the planet & you just serve up the closest one?

Re: Determining Nearest Coordinates

Posted: Thu Mar 24, 2011 3:23 pm
by JakeJ
They're spaced out all over the united states. So perhaps a person from Rogers, MN would be directed to the Minneapolis page, etc.

Re: Determining Nearest Coordinates

Posted: Thu Mar 24, 2011 3:33 pm
by pickle
So you want to direct them to the closest page geographically, without regard to political boundaries?

Once you have the location of the IP (say, "Rogers, MN"), you can send that to a location API (Yahoo! has one) to get the latitude & longitude. Once you have that, you can use a horribly complex query to find the closest page.

Re: Determining Nearest Coordinates

Posted: Wed Mar 30, 2011 5:57 pm
by flying_circus
Hey Jake,

I see that Pickle has already answered your question, but I was downloading mysql today and saw a blurb that reminded me of this post: "We have looked up your IP address using MaxMind GeoIP, and believe that these mirrors may be closest to you."

Not sure if you're working on a personal project or paid project, but it might be worth looking into. I just skimmed it real quick, but $20 for 50,000 queries might not be the end of the world depending on your traffic.

MaxMind GeoIP