How can I figure out a users postal code if I have their latitude / longitude location? Need help w

Posted by mike on Stack Overflow See other posts from Stack Overflow or by mike
Published on 2010-05-20T14:16:14Z Indexed on 2010/05/20 14:20 UTC
Read the original article Hit count: 220

Filed under:
|
|

I'm using HTML5 geolocation to collect the users lat / long and I need to figure out what their postal code is as well. I have a database of all the lat / long for each postal code in the US & Canada. How can I write a query to find out what their postal code is? Below, is an example of how the data is structured in the 'zips' table.

Country  PostalCode  Latitude  Longitude
USA      0051        40.813078 -73.046388
USA      00616       18.426456 -66.673779

I can't do a 'SELECT PostalCode FROM zips WHERE Latitude = user.lat AND Longitude = user.long'. I believe I need to find the nearest lat / long. Any suggestions on how I can write this?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about location