PowerShell : Get Distance Between Cities using Google Map Distance Matrix API


HOW IT WORKS :

Idea is to use the Google Map’s Distance Matrix API to calculate distance between two cities. Just to show you how it work, please navigate the below mentioned URL and pass necessary parameters. You’ll reach to an XML page which has all the necessary information.

Capture the content of this page using Powershell and the Fun begins 🙂

URL :  https://maps.googleapis.com/maps/api/distancematrix/xml?origins=goa&destinations=mumbai&mode=driving

gmap1

WHAT IS GOOGLE MAP DISTANCE MATRIX API ?

APIApplication Programming Interface is a set of functions and procedures that allow the creation of applications which access the features or data of an operating system, application, or other service.

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.

GET THE SCRIPT : Click here to go to my GitHub gist to get the code.

HOW TO USE IT :

By default you have to just provide Origin, Destination and Mode (‘Driving’,’Bicycling’,’Walking’) of Transportation  and you will get the distance in Unit Kilo Meters, like in the screenshot below.

gmap1

If you want to change the unit into miles use the switch -InMiles and distance would be converted into Miles

gmap1

Also, You’ll find Three Modes of transport (‘Driving’,’Bicycling’,’Walking’) available in the function for which you can calculate the time and distance.
gmap1

If in the case Google map doesn’t find any results (ZERO_RESULTS) for the values you passed in the Parameters, the Function will prompt you the same.

gm

Hope you guys find it useful. Thank you for Stopping by 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s