[nycphp-talk] Zipcodes calculation
Shannon Weyrick
weyrick at roadsend.com
Mon Jul 19 10:13:36 EDT 2004
Steve Manes wrote:
> Kshitij Bedi wrote:
>
>> I have a database with zipcodes and corresponding latitudes and
>> longitudes.
>> Can anyone suggest a mysql statement that can pull me all zipcodes
>> within 20
>> or 50 or 100 miles of a given zipcode
>
>
> You can do it as an imprecise rectangle, where latitude/longitude is
> plus/minus a certain number of minutes. Then you just do a SELECT for
> all zipcodes where the longitude/latitude falls within that rectangle.
> That's what a lot of job boards do and it usually works well enough for
> estimation, especially insofar as the longitude/latitude in those
> zipcode databases are only rough centers of mass. Otherwise, if you
> need more precision you'll need to use spherical geometry, which is very
> costly.
>
We needed this at Roadsend awhile back. I ended up implementing the
formula in a MySQL extension (as a function) so we could do direct
database queries on distance, based on zipcode/lat/long columns.
Not sure about attachments on the list, so I put the source up on the web:
http://www.roadsend.com/range.cc
The first commented line is the actual command I used to compile it.
Included in the other comments is how you can load the function into the
server.
Hope it helps.
-------------------
Shannon Weyrick
Roadsend, Inc.
Roadsend Compiler: The Commercial PHP Implementation
www.roadsend.com
More information about the talk
mailing list