Driving Distance Matrix API

Adding driving directions API would help to add predicted travel time & duration from a given origin point to a number of points. This REST API computes the distance and duration of a route between a source/primary position (geographical coordinates) and a list of all supplied secondary positions using to mode of route calculation i.e. optimal and shortest. Supported region (countries) are India, Sri Lanka, Nepal, Bangladesh & Bhutan. Please note that maximum number of points are limited to 100 only including source and secondary positions.

Security Type

  • License key based authentication
  • IP/domain based whitelisting

Input Method

GET

Contructing the request URL

Table 1. Requesting a Route
Element Value Description
Base URL https://apis.mapmyindia.com/advancedmaps/v1/ Production environment
Authorization "assigned_REST_license_key" The REST API license key authorized to access the resource
Resources distance_matrix to calculate the route & duration without considering traffic conditions.
distance_matrix_eta to get the updated duration considering live traffic; Applicable for India only “region=ind” and “rtype=1” is not supported. This is different from distance_matrix_traffic; since this doesn't search for a route considering traffic, it only applies delays to the default route.
distance_matrix_traffic to search for routes considering live traffic; Applicable for India only “region=ind” and “rtype=1” is not supported
Profile driving Meant for car routing
Coordinates "start and secondary coordinates" The coordinates pairs on which route is to be calculated. Minumum two pairs needed.

Example URL:

https://apis.mapmyindia.com/advancedmaps/v1/<assigned_license_key>/distance_matrix/driving/77.983936,28.255904;77.05993,28.487555;77.15993,28.587555?

where:

  • "distance_matrix" is the chosen resource.
  • profile is "driving"
  • "77.983936,28.255904" & other similar parts after it are the positions.

Note: The position input is in decimal degree notation of longitude,latitude.

Request Parameters

Mandatory Parameters
  1. lic_key: Allocated REST API license key. (part of URL).
  2. source: The first location is pair of comma separated longitude & latitude value which is taken as the source from which distance and ETA is to be calculated for the other locations specified in the rest of the ‘secondary_locations’ (part of URL).
  3. secondary_locations: The coordinates of rest of the locations whose distance from source will be calculated (part of URL). Format for each coordinate is the same as for the source, and they are semi-colon “;” delimited. For example 77.983936,28.255904;77.05993,28.487555.
Optional Parameters
  1. rtype type of route (integer) required for navigation, where values mean:
    • 0 optimal (default)
    • 1 shortest (it will calculate route by excluding access penalties like private roads, etc.)
  2. region(string): This parameter is optional for India; for other countries (Sri Lanka, Nepal, Bangladesh & Bhutan) this parameter is mandatory. Possible values are ind (for India, default), lka (for Sri Lanka) , npl (for Nepal) , bgd (for Bangladesh) and btn (for Bhutan)

Response Parameters

  1. responseCode: See the service dependent and general status codes.
  2. version: API’s version information.
  3. results: array of results, each consisting of the following parameters:
    • code: if the request was successful, code is ok.
    • durations: Duration in seconds for source to source (default 0), 1st, 2nd, 3rd secondary locations... from source.
    • distances: Distance in meters for source to source (default 0), 1st, 2nd, 3rd secondary locations... from source.

Response Type

JSON: response will served as JSON

Response Codes {as HTTP response code}

  • 200: To denote a successful API call.
  • 204: DB Connection error.
  • 400: Bad Request, User made an error while creating a valid request.
  • 401: Unauthorized, Developer’s key is not allowed to send a request.
  • 403: Forbidden, Developer’s key has hit its daily/hourly limit or IP or domain not white-listed.
  • 404: HTTP not found
  • 412: Precondition Failed, i.e. Mandatory parameter is missing
  • 500: Internal Server Error, the request caused an error in our systems.
  • 503: Service Unavailable, during our maintenance break or server down-times.

Sample Input

https://apis.mapmyindia.com/advancedmaps/v1/<lic_key>/distance_matrix/driving/90.33687,23.470314;90.379249,23.497178;90.497009,23.546286?rtype=1&region=bgd

Sample Response

{  "responseCode": 200,  "version": "191.17",  "results": {  "code": "Ok",  "distances": [  [  0,  6817.7,  20475.7  ]  ],  "durations": [  [  0,  1844.4,  5307.5  ]  ]  }  }