Search code examples
androiddistance

How to get straight distance between two location in android?


First read Question carefully ...

I need straight distance, not by walking,car,or etc.

Take a look to this image which given below,

Straight

Google provide us distance by car and driving.

But I don't want it, I want straight distance between two location (latitude - longitude).

Which is displayed as as RED LINE.

NOTE : I don't want to put red line on Google map, just want the Distance in Units(mile,km,etc.)


Solution

  • a = distance in degrees //meterConversion = 1609;
    
    b = 90 - latitude of point 1
    
    c = 90 - latitude of point 2
    
    l = longitude of point 1 - longitude of point 2
    
    Cos(a) = Cos(b)Cos(c) + Sin(b)Sin(c)Sin(l)
    
    d = circumference of Earth * a / 360 // circumference of Earth = 3958.7558657440545D km