How to use Google Maps Distance Matrix API

1
3375
Google Maps Distance Matrix API ASP.Net

Google’s Distance Matrix service computes travel distance and journey duration between multiple origins and destinations using a given mode of travel. In the following example, we will learn how to use Google Maps Distance Matrix API using C#.

Note: Route information, including polylines and textual directions, can be obtained by passing the desired single origin and destination to the Directions Service

Google maps javascript API v3 example distance matrix

You access the Distance Matrix API through an HTTP interface, with requests constructed as a URL string, using origins and destinations, along with your API key.

For example:- The following example requests the distance matrix data between Washington, DC and New York City, NY, in JSON format:

You must add an API key from your Google Maps APIs Premium Plan project if you want to include thedrivingOptions field in the DistanceMatrixRequest

Travel Modes

  • BICYCLING requests for bicycling directions via bicycle paths & preferred streets (currently only available in the US and some Canadian cities).
  • DRIVING (default) indicates standard driving directions using the road network.
  • TRANSIT requests directions via public transit routes. This option may only be specified if the request includes an API key. See the section on transit options for the available options in this type of request.
  • WALKING requests walking directions via pedestrian paths & sidewalks (where available).

Google maps distance matrix API example C#

Output

google maps distance matrix api example

Download Code

Conclusion
Here we have learned how to use google matrix javascript api. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

1 COMMENT

  1. Thanks for the great article. YOur code works fine. I have not used the sign part but with my API key, it works fine.

LEAVE A REPLY

Please enter your comment!
Please enter your name here