you need to calculate distance between couple of points/address? you need to set a shortest path route of your travelling? you need to deliver your goods to customer as soon as possible with lowest cost? google distance matrix api is a good solution for you. here i am going to show how to use google distance matrix api for any of your above purpose.
first of all you need to enable distance matrix in google. as your know, in order to use google service you must need a valid gmail id. let me consider you already have one.
first of all you need to enable distance matrix in google. as your know, in order to use google service you must need a valid gmail id. let me consider you already have one.
- now open to https://code.google.com/apis/console and log in your gmail account.
- from the left menu click service link and activate Distance Matrix API.
- Once you have activated, your API key is available from the API Access page, section: Simple API Access . And Distance Matrix API applications use the "Key for server apps" for me it looks like:
Key for server apps (with IP locking)
API key: |
AIzaSyCDB-C_sJ4fIENo0ku_ZM6-9despwBHvvo
|
---|---|
IPs: | |
Activated on: | Dec 15, 2013 6:39 AM |
mode
— when calculating directions which mode of transport will consider? . Valid values are:
driving
(default) indicates standard driving directions using the road network.walking
bicycling
only available in the US and some cities in Canadia
You can receive two different types of output of distance:
1. JSON Output
2. XML Output
All parameters are remain same except json/xml in request url.
A simple distance matrix example(JSON Output):
https://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&mode=bicycling&language=fr-FR&key=AIzaSyCDB-C_sJ4fIENo0ku_ZM6-9despwBHvvo
https://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&mode=driving&language=fr-EN&key=AIzaSyCDB-C_sJ4fIENo0ku_ZM6-9despwBHvvo
A simple distance matrix example(XML Output):
https://maps.googleapis.com/maps/api/distancematrix/xml?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&mode=driving&language=fr-EN&key=AIzaSyCDB-C_sJ4fIENo0ku_ZM6-9despwBHvvo
You can also get direction request:
https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&key=AIzaSyCDB-C_sJ4fIENo0ku_ZM6-9despwBHvvo&avoid=highways&mode=bicycling
More documentation of Google Distance Matrix API is here.
Similar to Google Matrix API mapquest documentation is here.