Page 1 of 1

Distance between two zips using Longitude/latitude

Posted: Thu May 06, 2010 8:50 am
by Kurt
I need some math help. I need to make a BR program figure out the distance between two zip codes using longitude and latitude.

Using these two zips
Zip code 61360 is Seneca Illinois, Lat is 41.311N Long is -88.609W
Zip Code 60541 is Newark Illinois, Lat is 41.537N Long is -88.583W

Anyone know how to do the math to tell me the distance in miles between these two zip codes??? :?

Kurt

Posted: Thu May 06, 2010 9:05 am
by John
this might help:

wolframalpha can be used to determine all kinds of mathmatecial calculations
passing:
41.311deg N, 88.609deg E, 41.537deg N, 88.583deg E
to wolframalpha returns:

http://www89.wolframalpha.com/input/?i= ... 8.583deg+E

you could probably use cURL or new HTTP features to access this web site programmaticly or something.

Posted: Thu May 06, 2010 9:10 am
by Kurt
Hi John,

Thats pretty cool, but I need to know the formula to calculate that. I need to develop a program that allows a user to enter two zip codes which I then use to look up the longitude and latitude values in a file.

Then I need to calculate the distance in miles between those two and show the user.]

I'm on BR 3.93 or something like that.....yeah I know, really old.

I need BR code to do this, and I'm no math wiz.

Kurt

Posted: Thu May 06, 2010 9:12 am
by GomezL
Zip1$, LAT1 & LONG1 are required
Zip2$, LAT2 & LONG2 are required

I am not exactly sure about the "N" & "W", but Both LAT & LONG need to be (+) Values IE:

"61360" LAT =41.3267 LONG =88.6042
"60541" LAT =41.5266 LONG = 88.5274

100 LET CNV1=180/PI
110 LET A=SIN(LAT1/CNV1)*SIN(LAT2/CNV1)+COS(LAT1/CNV1)*COS(LAT2/CNV1)*COS(LONG2/CNV1-LONG1/CNV1)
120 LET DIST=3959*ATN(SQR(ROUND((1-A**2),10))/A)


Ever wondered when you would use your math from high school in real life?

The distance between "61360","60541" = 7.302294 miles

Posted: Thu May 06, 2010 9:18 am
by Kurt
I distinctly remember sitting in math class thinking to myself "I'm never going to need to know how to do this".....

Thanks guys, I'll give this a try.

Kurt

Posted: Thu May 06, 2010 10:35 am
by Kurt
Thanks guys, the formula provided above works.

Funny though, mapquest says that these towns are 17 miles apart....I know traveling on roads would be longer than the "straight line" between two points.

I'll have to check into the validity of the data I have. But the formula works.

Thanks
Kurt