2

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 between two points. Now how to calculate distance of the path that i have drawn? Please any body help!

Thanks & Regards!

Sudipta Som
  • 6,537
  • 9
  • 43
  • 67

3 Answers3

5

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.)

5

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.

TigrouMeow
  • 1,038
  • 4
  • 19
  • 30
  • I want the distance by road between two point, so that i can calculate the fair based on exact distance.. – Sudipta Som Jan 27 '11 at 07:57
  • Yes, Google Directions give you the distance by driving too. The fare you mean? For the fuel, you'll have to compute this by yourself depending on the car, but Google Directions will also give you the road fares if there are any :) – TigrouMeow Jan 27 '11 at 08:10
  • @SudiptaforAndroid, hi can you provide helpful answer of this question that what you had used in your case. thank you. – user609239 Feb 14 '12 at 13:15
  • is the result in meters? – Display Name Mar 23 '14 at 22:00
4

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.

Aman Alam
  • 11,231
  • 7
  • 46
  • 81