# Calculate distance between two Lattitude Longitude Coordiantes using ColdFusion 6

I see there are many formulae on this site for doing this. But I need to know how to do it using
Cold Fusion.

I will have two coordinates I need to calculate the distance dynamically as I run a Schedulted CF task to mail members of the data base:- .  to see if a posted opportunity is within their defined area - they specify how many KMS they are prepared to travel.

Eg I will have

MemberLat = "37.6922361"
MemberLng = "-97.3375448"

OpportunityLat = "56.1303660"
OpportunityLng = "-106.3467710"

How to calulate the distance between in Kilometers using CF6?

###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
You need the equation, then it's all down hill.

Here is one in SQL

http://www.petefreitag.com/item/622.cfm

Below is code in Coldfusion...

http://www.zipcodeworld.com/samples/distance.cfm.html

``````<cfset radlat1 = ((pi() * lat1)/180)>
<cfset radlat2 = ((pi() * lat2)/180)>
<cfset radlon1 = ((pi() * lon1)/180)>
<cfset radlon2 = ((pi() * lon2)/180)>
<cfset theta = lon1-lon2>
<cfset radtheta = ((pi() * theta)/180)>
``````

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Owner and FounderAuthor Commented:
Thanks it brings back a result ok.  Do you know if the CF code returns miles or kilometers. It does not say in the documentation. Give it talks about zip codes - does this mean miles?

Thanks
Ian
Commented:

Yea, it's miles.   Just convert the result to kilometers..
Owner and FounderAuthor Commented:
Quick response
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.