How to get straight distance between two location in android?

后端 未结 3 1648
遇见更好的自我
遇见更好的自我 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:38

    Distance you find with following code. You just need to get two geoPoint's latitude and longitude. and use that in following calculation to get distance.

     R = 6371; // km
     d = Math.acos(Math.sin(lat1)*Math.sin(lat2) + 
                  Math.cos(lat1)*Math.cos(lat2) *
                  Math.cos(lon2-lon1)) * R;
    

    That will be return distance after all calculation.

    R is the radius of surface in KM, need to use in calculation and you try this. I hope it is useful for you.

提交回复
热议问题