Forums

This topic is locked

Zip Code formula

Posted 17 Jan 2002 04:28:55
1
has voted
17 Jan 2002 04:28:55 lane c posted:
Does anyone have the formula or a scrpit for calculating zip code distances. I want to be able to have users enter their zip code and enter a distance (a radius) and get a list of all the zip codes within that distance. I have a database, I just need the formula.

Thanks,
Lane

Replies

Replied 17 Jan 2002 15:01:28
17 Jan 2002 15:01:28 Kevin Vogler replied:
This is from "John" on Google Groups UD

This is the link to the zipcode/lat/long db
www.census.gov/ftp/pub/tiger/tms/gazetteer/

That's the zip code database, and here's the code to determine whether a
city is within 150 miles, for example:

' THIS VARIABLE SETS THE RADIUS IN MILES
iRadius = 150

istartlat=Session("lat"
istartlong=Session("long"

LatRange = iradius / ((6076 / 5280) * 60)
LongRange = iRadius / (((cos(cdbl(iStartLat * _
3.141592653589 / 180)) * 6076.) / 5280.) * 60)

LowLatitude = istartlat - LatRange
HighLatitude = istartlat + LatRange
LowLongitude = istartlong - LongRange
HighLongitude = istartlong + LongRange
SELECT *
FROM Locations
WHERE Latitude <= [HighLatitude]
AND Latitude >= [LowLatitude]
AND Longitude >= [LowLongitude]
AND Longitude <= [HighLongitude]

Hope this helps. I haven't played with it myself. I'm keeping it for a rainy day
Kevin

Reply to this topic