|
Go
![]() |
New
![]() |
Search
![]() |
Notify
![]() |
Tools
![]() |
Reply
![]() |
|
|
Member |
I was trying to calculate distance by using latitude and longtitude. Does anyone has the formula or ways to do so? I'd really appreciated.
|
||
|
|
Virtuoso |
how about google distance gives you Haversine formula:
R = earth’s radius (mean radius = 6,371km)
Δlat = lat2− lat1
Δlong = long2− long1
a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
c = 2.atan2(√a, √(1−a))
d = R.c
(Note that angles need to be in radians to pass to trig functions).
JavaScript: var R = 6371;
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad();
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
and meridian I'm not sure if you will be able to do this in WF, but you might be able to do this.
|
|||||||
|
|
Virtuoso |
http://www.mathforum.com/library/drmath/view/51711.html
The above gives a discussion of the issue, Of course how to calculate sines and cosines to do the formula should be interesting. Leah |
|||
|
|
Expert |
Adong,
See the discussion on this subject from February this year. T Old FOCUS coders never die, they just become functionally stable. (Tony A
|
|||||
|
|
Platinum Member |
Here's what I came up with after much discussion in February and a little help from some college math professors.
-SET &PI = 3.1415926535897932384626433832795; -* Earth's mean radius in km 6371 -* Earth's mean radius in mi 3956 -SET &Earth_R = 3956; DEFINE FUNCTION F_SIN(angle/I3) Rads/D33.12 = angle / 180 * &PI ; F_SIN/D20.12 = Rads - ((Rads ** 3)/(1*2*3)) + ((Rads ** 5)/(1*2*3*4*5)) - ((Rads ** 7)/(1*2*3*4*5*6*7)) + ((Rads ** 9)/(1*2*3*4*5*6*7*8*9)) + ((Rads ** 11)/(1*2*3*4*5*6*7*8*9*10*11)) + ((Rads ** 13)/(1*2*3*4*5*6*7*8*9*10*11*12*13)); END -* -RUN -* DEFINE FUNCTION F_COS(angle/I3) Rads/D33.12 = angle / 180 * &PI ; F_COS/D20.12 = 1 - ((Rads ** 2)/(1*2)) + ((Rads ** 4)/(1*2*3*4)) - ((Rads ** 6)/(1*2*3*4*5*6)) + ((Rads ** 8)/(1*2*3*4*5*6*7*8)) - ((Rads ** 10)/(1*2*3*4*5*6*7*8*9*10)) + ((Rads ** 12)/(1*2*3*4*5*6*7*8*9*10*11*12)); END -* -RUN -* DEFINE FUNCTION F_DIST(Lat1/D16.6, Long1/D16.6, Lat2/D16.6, Long2/D16.6) Earth_R/D8 = 3956; dLat/D20.6 = Lat2 - Lat1; dLong/D20.6 = Long2 - Long1; F_DIST/D20.4 = SQRT(dLat * dLat + dLong * dLong) * 1/(F_COS(dLat / 2)) / 360 * (2 * &PI * Earth_R); END -* -RUN -* TABLE FILE CAR SUM -**************SIN COS COT******************************** -**************DISTANCE CALCULATOR************************ COMPUTE LON1/D20.8 = 94.9202; COMPUTE LON2/D20.8 = 94.9741; COMPUTE LAT1/D20.8 = 29.3969; COMPUTE LAT2/D20.8 = 29.3676; COMPUTE DLON/D20.8 = LON2-LON1; COMPUTE DLAT/D20.8 = LAT2-LAT1; COMPUTE DIST/D20.8 = F_DIST(LAT1, LON1, LAT2, LON2); BY COUNTRY NOPRINT WHERE RECORDLIMIT EQ 1 END Hope this helps Glenda Glenda Production 5.3.6 - UNIX |
|||
|
|
Expert |
Adong, i think we would all agree that it depends on how much accuracy you need.
Do you need to correct for the curvature of the earth, or not? If not, then plain old Pythagoras should be good enough, after xlating your latlongs into radians. If your distances are all within your country (you don't say what country you're in), you can decide just how much agony you need to go thru. If your distances are crossing continents, then Tony and Glenda have done your heavy lifting for you. (looks like a great first entry for the new wf wikipedia!)
|
|||||
|
|
Master |
Did you mean to say
? |
|||
|
|
Member |
Glenda,
Thank you very much for your post. It works perfect. I really appreciate your help. Maggie |
|||
|
|
Platinum Member |
Maggie,
Glad I was able to help. Glenda. Glenda Production 5.3.6 - UNIX |
|||
|
|
Expert |
Hi Glenda,
I think that this topic is one worthy for writing an article about for the FOCUS on Developers area. I'm sure Kathleen would agree as it is bound to come up time and again. What do you reckon? T (currently in Vegas!! Old FOCUS coders never die, they just become functionally stable. (Tony A
|
|||||
|
|
Platinum Member |
Tony,
I'm just a puzzle solver. The more challenging the better. When a COBOL programmer said WeBFOCUS code was too limited to perform distance calculations, it was like waving a red flag in front of a bull (or a stubborn Irish gal). I don't know the first thing about writing an article. If you want to help me or write it yourself, I won't mind. It sure would save others from what I had to go through to find the information. And don't rub it in! I couldn't make Las Vegas this year and I so wanted to meet you and the others. Glenda Glenda Production 5.3.6 - UNIX |
|||
|
|
Virtuoso |
I discussed this issue (more in general) with some people from IBI in Vegas.
It is indeed not easy to use recursive programming within webfocus and create formulas for several mathematic or financial functions like IRR and FV etc. But I'm sure that they will see it as a challange to forfill our wishes on this point if we ask them
|
|||||||
|
|
Expert |
Hi Glenda,
I agree totally, just tell me that "it can't be done" and I will try to find a way. Just as when Susannah said that trig functions are not possible in Feb in answer to the original question. T Old FOCUS coders never die, they just become functionally stable. (Tony A
|
|||||
|
|
Platinum Member |
Tony,
You've got me pegged! Glenda Glenda Production 5.3.6 - UNIX |
|||
|
|
Expert |
T and Glenda... i see a really great Summit presentation on this subject for the 2 of you to do together for 2008...
and there's a chance, i hear, that Summit might be in Dallas... close enough for "Red" to get there.
|
|||||
|
|
Platinum Member |
Susannah,
YOu are so perceptive. I never said a thing about being a redhead. But yes, that's where the stubborn streak comes from. I like your idea. I'm game if Tony is. Glenda Production 5.3.6 - UNIX |
|||
|
| Previous Topic | Next Topic | powered by eve community |
| Please Wait. Your request is being processed... |
|

