The Distance Matrix API is a service that provides travel distance and time for a matrix of origins and destinations. The API returns information 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..
Follow the below steps
First of all , you have to create project in Google Console.
After creating project in Google console , you have to enable Distance Matrix API from Google Api & SDK.


Click Distance Matrix API then Click on Enable button then it would activate the Places Api .
Go to the APIs & Services > Credentials page Go to Credential Page.
On the Credentials page, click Create credentials > API key.
The API key created dialog displays your newly created API key.
Click Close
You can ask your queries