1

I am fairly new to android and i have been following this tutorial on getting maps to display.

i was wondering is there a way that when you get the directions you can return the driving (not straight line) distance between point A and B and have it displayed in a text view?

Thanks.

Mr.stark
  • 31
  • 5
  • 1
    You could use the Distance Matrix API (part of the Web APIs) in order to get the distance. Note you can specify the mode (driving, walking, etc). See documentation here: https://developers.google.com/maps/documentation/distancematrix/ – Daniel Nugent May 25 '15 at 21:17

1 Answers1

1

Use the following:

float[] result = new float[0];
Location.distanceBetween(startLatitude, startLongitude, endLatitude, endLongitude, result);
//The computed distance is now stored in results[0].

Source

Also you can use Google Maps Android API Utility Library: It has static method to compute distance.

SphericalUtil.computeDistanceBetween(from,to)
//Returns the distance between two LatLngs, in meters.

Source

fida1989
  • 3,234
  • 1
  • 27
  • 30
  • 1
    Note that this is just the distance of a straight line between two points. I believe the OP wants the distance of the driving directions from point A to point B. – Daniel Nugent May 25 '15 at 20:54
  • @DanielNugnet Yes that's right, would like if possible to the distance to drive. – Mr.stark May 25 '15 at 20:59