How to get straight distance between two location in android?

后端 未结 3 1506
遇见更好的自我
遇见更好的自我 2021-01-31 12:54

First read Question carefully ...

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

Take a look to this image which given be

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-31 13:37

    ANDROID

    double distance
    
    Location locationA = new Location(“point A”)
    
    locationA.setLatitude(latA);
    
    locationA.setLongitude(lngA);
    
    Location locationB = new Location(“point B”);
    
    locationB.setLatitude(latB);
    
    LocationB.setLongitude(lngB);
    
    distance = locationA.distanceTo(locationB);
    

    MATHEMATICALY

    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
    

提交回复
热议问题