user2440685
user2440685

Reputation: 25

Calculate route's distance

I have to calculate a route's distance, which was drawn with the following code:

map.drawRoute({
            origin: [lat1, lng1],
            destination: [lat2, lng2],
            travelMode: 'driving',
            strokeColor: '#000',
            strokeOpacity: 0.6,
            strokeWeight: 3
}); 

I used the gmaps.js library for it.

Upvotes: 1

Views: 133

Answers (1)

Sébastien Renauld
Sébastien Renauld

Reputation: 19662

First off, there is no such method in the raw Google Maps API. You are using a third-party library from hpneo.

Secondly, this library allows you to set a callback in the object you pass. I cannot test the lib from here. You may want to try this:

 map.drawRoute({
      origin: [lat1, lng2],
      destination: [lat2, lng2],
      travelMode: 'driving',
      callback: function() { console.log(arguments); }
 });

From there, arguments will contain what the callback was called with, which may or may not contain the composite distance.

Upvotes: 1

Related Questions