Travel Distance between two Lat and Long

Harsha M V picture Harsha M V · Jan 29, 2013 · Viewed 11k times · Source

I am looking to calculate and give the distance between two sets of Lat and Long for travel on Road.

I have had a look at the Google's Directions and Distance Matrix API. And also done a lot of other questions on SO.

But i am not able to figure out the best possible way to do it, you need to calculate the distance to around 20-25 locations at each time.

We are building a travel app that requires this information for the user on Android device from where he is.

Answer

rumburak picture rumburak · Feb 19, 2013

If You are looking for driving distance NOT shortest distance then You can try to call API service with URL like:

http://maps.googleapis.com/maps/api/distancematrix/json?origins=54.406505,18.67708&destinations=54.446251,18.570993&mode=driving&language=en-EN&sensor=false

This will result in JSON like this:

{
   "destination_addresses" : [ "Powstańców Warszawy 8, Sopot, Polska" ],
   "origin_addresses" : [ "majora Henryka Sucharskiego 69, Gdańsk, Polska" ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "24,7 km",
                  "value" : 24653
               },
               "duration" : {
                  "text" : "34 min",
                  "value" : 2062
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}

Result distance is actual road distance between two locations.

You can find more details in The Google Distance Matrix API