- Home >
- Documentation >
- Services >
- getdistance
getdistance
This function issues a distance matrix request.
Usage
Parameters
- options {google.maps.DistanceMatrixRequest}
Note
- options.origins and options.destinations values are converted into google.maps.LatLng.
- This function doesn't initialize the map.
Example
This example returns the distance from an origin to a destination
$("test").gmap3({ getdistance:{ options:{ origins:["Marseille"], destinations:["Paris"], travelMode: google.maps.TravelMode.DRIVING }, callback: function(results, status){ var html = ""; if (results){ for (var i = 0; i < results.rows.length; i++){ var elements = results.rows[i].elements; for(var j=0; j<elements.length; j++){ switch(elements[j].status){ case "OK": html += elements[j].distance.text + " (" + elements[j].duration.text + ")<br />"; break; case "NOT_FOUND": html += "The origin and/or destination of this pairing could not be geocoded<br />"; break; case "ZERO_RESULTS": html += "No route could be found between the origin and destination.<br />"; break; } } } } else { html = "error"; } $("#test").html( html ); } } });