Does ayone know of any zip code radius search information that relates to PHP and MySQL?
I have found several articles but mainly related to Cold Fusion
I want to build a script that will do a radius search and return all the zip codes withing the given distance.
I have a copy of the US zip codes containing State, City, Longitude, and Latitude. I also have informatin on the Haversine Formula... I just don't undertand it and how to use it in PHP and MySQL.
Any help will be greatly appreciated.
Zip Code Radius Calculations
Moderator: General Moderators
Yes, the CF script appears to be complete.
here is the db query code:
How would you convert that to PHP and MySQL commands?
.
here is the db query code:
Code: Select all
<cfquery datasource="#dsname#" name="getlocs">
SELECT zipcode, latitude, longitude, statename, city,
ROUND((ACOS((SIN(#passedzip.latitude#/57.2958) * SIN(latitude/57.2958)) +
(COS(#passedzip.latitude#/57.2958) * COS(latitude/57.2958) *
COS(longitude/57.2958 - #passedzip.longitude#/57.2958))))
* 3963) AS distance
FROM zipcodes
WHERE (latitude >= #passedzip.latitude# - (#passedradius#/111))
And (latitude <= #passedzip.latitude# + (#passedradius#/111))
AND (longitude >= #passedzip.longitude# - (#passedradius#/111))
AND (longitude <= #passedzip.longitude# + (#passedradius#/111))
ORDER BY distance
</cfquery>How would you convert that to PHP and MySQL commands?
.
- smpdawg
- Forum Contributor
- Posts: 292
- Joined: Thu Jan 27, 2005 3:10 pm
- Location: Houston, TX
- Contact:
Here is a php class to do zip code disctance calculations and a database to go with it.
http://phpclasses.spunge.org/browse/package/522.html
or the authors site
http://www.sanisoft.com/ziploc/
http://phpclasses.spunge.org/browse/package/522.html
or the authors site
http://www.sanisoft.com/ziploc/