Distance from zip/city?

1. Senior Member
Join Date
Dec 1969
Posts
376

## Distance from zip/city?

Does anyone know how to go about figuring out the distance from one zipcode to another, or one city to another? I have a client that really wants to have this feature implemented on their site. I&#039;ve seen it done in so many other places, how can you do it? It would be nice if it was just a simple formula dealing with zip codes, but I&#039;m going to guess that that isn&#039;t quite it.

2. Senior Member
Join Date
Dec 1969
Posts
1,671

## RE: Distance from zip/city?

check it out:http://www.bridger.com/products.htm

3. Senior Member
Join Date
Dec 1969
Posts
96,118

...and my "not as easy as you think" answer.<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
376

I&#039;m guessing you need a zip code DB with latitude and longitude measurements, from there getting the distance?

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Did you guess that...

before or after looking in the Advanced forum???<BR><BR>If before, give yourself two points. But then go look at my remarks about why even *that* has major flaws.<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
376

## RE: Did you guess that...

Yep, I guessed it beforehand. Of course reading your post afterwards highlighted some of the trouble areas. It would just be so much nicer to be able to make my own rather than buy one of those expensive components.

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## RE: Did you guess that...

&#062; It would just be so much nicer to be able to make my own <BR><BR>Not really all that hard if <BR><BR>(1) You can find the database of zip codes vs. Latitude/Longitude<BR>(2) You are willing to approximate the answer(s)...should be adequate for all but Alaska.<BR><BR>lat = latitude1 - latitude2<BR>lon = longitude1 - longitude2<BR>distance = SQR( lat*lat + lon*lon ) * factor<BR><BR>And then just do ORDER BY distance in the SQL query. Really easy in a Stored Proc. But do-able even in pure SQL.<BR><BR>Probably want to pre-qualify records to be examined by making sure the zips are within so many degrees (or minutes?) of the target.<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•