# zip radius class return distance calculation also?

• Aug 10, 2007, 17:49
atDev
zip radius class return distance calculation also?
We use the following: http://www.phpclasses.org/browse/package/522.html

However, it doesnt return the distance that the zip is from the input zip code.

It uses this calculation/query:

Anyway to get it to return also the distance?
• Aug 10, 2007, 18:25
dc dalton
methinks their distance calc is incorrect (could be wrong), here's mine:

Code:

`SQRT (((69.1*(latitude-{\$from_latitude})) ^ 2) + ((53*(longitude-{\$from_longitude})) ^ 2))`
• Aug 10, 2007, 20:37
atDev
Ok but do you know how you might return the distance also?
• Aug 10, 2007, 20:37
atDev
Also in yours where are you suppose to enter their entered radius (from the input)?
• Aug 11, 2007, 15:07
Cborrow
I used this to do a search from one zipcode to another (using geological locations) I had a large database filled with zipcodes as well as there city, state, lon and lat.

zipcodes is the listing of zipcodes and there city state and other things, and the locations is a database of locations for

Edit: I believe this is the US zipcode listing that I used. http://www.zip-codes.com/

Code:

`SELECT z.zipcode, z.lon, z.lat, l.name, l.id, l.address, l.city, l.state, l.zip FROM zipcodes = z, locations = l WHERE(POW((69.1 * (z.lon - '\$lon') * cos(\$lat / 57.3)), 2) + POW((69.1 * (z.lat - '\$lat')), 2)) < (\$miles * \$miles) GROUP BY name`
• Aug 11, 2007, 15:24
dc dalton
Quote:

Originally Posted by atDev
Ok but do you know how you might return the distance also?

Sure do, you also use this in the select:

PHP Code:

``` SQRT (((69.1*(latitude-{\$from_latitude})) ^ 2) + ((53*(longitude-{\$from_longitude})) ^ 2)) AS \"calc\""  ```
My PHP fields are in the {}

and as far as how far to search you add this to the where clause:

PHP Code:

``` AND SQRT (((69.1*(latitude-{\$from_latitude})) ^ 2) + ((53*(longitude-{\$from_longitude})) ^ 2)) <={\$miles_to_use}"  ```
• Aug 14, 2007, 06:59
atDev
Do you know how this performs on large sets of data?
• Aug 16, 2007, 21:08
atDev
Do you know how you can easily change this between miles and kilometers?