We help IT Professionals succeed at work.

Latitude ,Longitude to Distance Conversion.

naomanahmed
naomanahmed asked
on
62,759 Views
Last Modified: 2012-06-27
Can any body tell me how to calculate distance between two points (latitude ,longitude given)on a map.
Basically I want to know that with the difference of one degree how much will be the difference in Distance.
That is One Degree = How much Distance(of course radius).
Comment
Watch Question

This can be performed using a tricky and trial based formula.

First you need to know LT and LG of any two different locations. then you calculate the difference between the two by static methods. After that you may check the LT & LG of another city which is say 100 kms away. the change in LT & LG will be found out. The resulting figure may be used in the form of statement in automated calculations.

It is trial based method, but I am sure it will do the job. If anyone has a formula to achieve this result, s/he is most welcome.

LT & LG can now be grabbed in the web based systems also using IP address of the person. for more information see www.geoselect.com (amazingly accurate if using DialUp)
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
Here is a formula for calculating the distance between a set of coordinates:


C = sin(Latitude1/57.3) * sin(Latitude2/57.3) +
     cos(Latitude1/57.3) * cos(Latitude2/57.3) *
        cos(Longitude2/57.3 - Longitude1/57.3)

Distance = 3959 * acos(C)

Commented:
Hi folks,

I have question about the last solution proposed.

The distance is in mile or Km?

Those it's take in consideration the elevation?

And, it's relevant to take care of the elevation?

Thank you.

Commented:
The distance is returned in miles.  No it does not consider elevation.

Commented:
Thank Waylen,

When I try that formula with 1 degree of delta I got 69.09249563699 and not 70.

Three more questions.

Why 57.3?
Why 3959?
Do you have any web reference I can look to learn more about that very subject?

Commented:
Never mind, I figure myself.

3959 Earth radius in miles
57.3 Convertion from deg to rad. (Or 180/pi)

In a attemp to get the must precise values, I check the web for more accurate values.  I share it with you.

Earth radius, source ssd.jpl.nasa.gov/phys_props_earth.html
6378.136 Km

Pi values, source www.ecst.csuchico.edu/~tchung/pi_val.html
3.14159265358979

The best value I got from those number are 1 degree = 69.170713875962 Miles

That assume Earth is a perfect sphere.  Maybe this is why I don't got 70?  How can we say that 1 degree = 70 miles?  Does my answer is more accurate?

Commented:
regarding using lat-long of two discrete locations to calculate the distance, does anyone have a handy excel formula to accomplish this?

Commented:
I am interested in this also...

PS I have heard of this deber expert - he is also an expert in aviation and fencing.

I am newbie in GPS&GIS, Who can tell me
1. What route/road information can I get from GIS by given GPS information?
2. I hope to get the information such as route name, segment, lane, building material and etc from the GIS system.
    which GIS system should I purchase?

Thanks.

Commented:
Hope this helps, is a function (VBA for Excel) that calculates the distance between two points (Lat1,Lon1) <->(Lat2,Lon2) using the great circular method, I have compared the results with Mapinfo distance tool and it is quite close.

Cheers
____________________________________________________________________________________________________________

Private Function CalculateDistance(Lat1, Lon1, Lat2, Lon2) As Double
        Dim a, b, c As Double
        Const PI = 3.14159265358979
        Const RadiusEarth = 6371000
        ' 1 Degree is 69.096 miles, 1 mile is 1609.34 m
        a = Cos(Lat1 * PI / 180) * Cos(Lat2 * PI / 180) * Cos(Lon1 * PI / 180) * Cos(Lon2 * PI / 180)
        b = Cos(Lat1 * PI / 180) * Sin(Lon1 * PI / 180) * Cos(Lat2 * PI / 180) * Sin(Lon2 * PI / 180)
        c = Sin(Lat1 * PI / 180) * Sin(Lat2 * PI / 180)
        If (a + b + c) >= 1 Or (a + b + c) <= -1 Then
            CalculateDistance = 0
        Else
            CalculateDistance = Application.WorksheetFunction.Acos(a + b + c) * RadiusEarth 'Distance will be in meters
        End If
End Function
Heres a VB6 function to do it:

Public Const gEARTH_RADIUS_METRES = 6378007
Public Const gEARTH_CIRCUM_METRES = gEARTH_RADIUS_METRES * 2 * gPI
Public Const gMETRES_PER_LAT_DEGREES = 111113.519

Public Function GetDistance(dX1 As Double, dY1 As Double, dX2 As Double, dY2 As Double) As Double
    Dim dDeltaX As Double
    Dim dDeltaY As Double
    Dim dDeltaXMeters As Double
    Dim dDeltaYMeters As Double
    Dim dMetersPerDegreeLong As Double
    Dim dCenterY As Double
   
    dDeltaX = Abs(dX2 - dX1)
    dDeltaY = Abs(dY2 - dY1)
    dCenterY = (dY1 + dY2) / 2
    dMetersPerDegreeLong = MetresPerDegreeLong(dCenterY)
    dDeltaXMeters = dDeltaX * dMetersPerDegreeLong
    dDeltaYMeters = dDeltaY * gMETRES_PER_LAT_DEGREES
    GetDistance = Sqr(dDeltaXMeters ^ 2 + dDeltaYMeters ^ 2)
End Function

Public Function MetresPerDegreeLong(ByVal dLat As Double)
    MetresPerDegreeLong = (Cos(dLat * (gPI / 180)) * gEARTH_CIRCUM_METRES) / 360
End Function

Commented:
So do you have a straight excel formula for it or can you only do it through the VBA

Commented:
Excel does not have a straight formula for that but this is what you can do:

 Insert a Module
Go Alt+F11 to access the MS Visual Basic environment, at the extreme left select the Workbook you want to include the formula and Right-Click it, then insert Module and Copy and Paste the formula that I submitted before. Next step is changing the scope of the Formula replacing Private with Public and you should be able to use the formula CalculateDistance(Lat1, Lon1, Lat2,Lon2) just like any other formula in excel.

This will allow you to use the formula just in the workbook where you inserted the module. If you want this formula to be available always then you shuold convert the module to an Add-In and make sure you set the reference accordingly.

Hope this helps.

Just a comment for the formula submitted by f_rodriguez, that formula assumes that the earth is flat and is quite close to the great circular method for small distances, however once the points are about 20 km from each other, the pitagoras aproximation starts to  getting off of the real value.

Best Regards
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.