-
Notifications
You must be signed in to change notification settings - Fork 149
API: Distance Matrix
Yass edited this page Aug 1, 2017
·
4 revisions
The Google Maps Distance Matrix API is a service that provides travel distance and time for a matrix of origins and destinations. The information returned is based on the recommended route between start and end points, as calculated by the Google Maps API, and consists of rows containing duration and distance values for each pair.
Let's assume we want to find distance between two points:
Batilly @ 49.171020, 5.969358
and
Aachen @ 50.775346, 6.083887
Create the request:
DistanceMatrixRequest request = new DistanceMatrixRequest()
{
WaypointsOrigin = new List<Location> { new LatLng(49.171020M, 5.969358M) },
WaypointsDestination = new List<Location> {new LatLng(54.555393M, 23.362615M) },
Sensor = false
};
Make the request:
var response = new DistanceMatrixService().GetResponse(request);
Display the results:
Console.WriteLine(response.Rows.First().Elements.First().distance.Text);
Console.WriteLine(response.Rows.First().Elements.First().duration.Text);
It doesn't work anymore, it returns null.
Output:
1,677 km
16 hours 19 mins