Distance between two map point or lat long in android

后端 未结 3 1039
挽巷
挽巷 2021-01-15 16:39

I am trying to calculate the distance between two map point using Google Map in android. I have used two lat long value to put two map pin and also able to draw a route betw

相关标签:
3条回答
  • 2021-01-15 17:06

    You probably want to use the Google Directions API to known the real distances between two GPS locations. If you want the "crow-fly" distance, Sheikh's answer is perfect.

    0 讨论(0)
  • 2021-01-15 17:13

    The easiest way to get a crow-flies distance between two locations is in android.location.Location. The static function distanceBetween will do what you want.

    http://developer.android.com/reference/android/location/Location.html

    (I do not know how to reply to a post, but I want to say for anyone viewing this thread after the fact that Sheikh's "dirty" answer is not correct; he is calculating the rectangular distance, which will vary from the correct answer depending on where you are on the globe. If you REALLY want to do the math yourself, you need to use this: http://www.movable-type.co.uk/scripts/latlong.html . But you don't really want to do the math yourself. Really.)

    0 讨论(0)
  • 2021-01-15 17:16

    I was also in a situation like this some days ago, and believe me, its such a headache.

    Still, I feel following links will help you:

    1. Wikipedia explanation and formulae
    2. All about Latitude and Longitude on
    3. The dirty way, calculate distance by converting latitude/longitude difference to kms/miles

    I hope it helps a bit.

    0 讨论(0)
提交回复
热议问题