getDistance Method for Mappls Web Maps¶
Easy To Integrate Distance Matrix APIs & Map SDKs For Web Applications
Powered with India's most comprehensive and robust mapping functionalities. Now Available for 200+ nations and territories accross the world.
Getting Access¶
Before using the API in the your solution, please ensure that the related access is enabled in the Mappls Console, within your app - be it for Mobile OR Web or Cloud integration.
-
Copy and paste the key from your
credentials
section from your API keys into theaccess_token
query parameter.- Your static key can be secured by whitelisting its usage for particular IPs (in case of cloud app usage) OR a set of domains (in case of a web app)
- Your static key obtained from your Console is to be passed as a query parameter:
access_token
.
-
The sample codes are provided on our domain to help you understand the very basic functionality of Mappls Distance Method.
Authentication Object - access_token
mandatory query parameter.¶
access_token
: "hklmgbwzrxncdyavtsuojqpiefrbhqplnm".
Document Version History¶
Version | Last Updated | Team | Author | Remarks |
---|---|---|---|---|
1.0 | 07 Aug 2025 | SDK Product Team | Prabhjot Kaur (PK) | OAuth 2 |
Introduction¶
This method, offered by Mappls web plugins , computes the routable distance and duration between a set of source/primary positions and a list of all supplied secondary positions using two mode of route calculation i.e. optimal OR shortest. The method also takes into account different modes of transport like 4 wheelers, two wheelers + more. Please note that maximum number of points are limited to 100 only including source and secondary positions.
The method offers the following basic functionalities:
1. The method computes the distance and duration from origin to number of supplied destinations on maps.
2. The ability to set the vehicle profile like driving, biking and trucking.
3. Easily set the resource for traffic and ETA information.
4. The method also has 'many to many' functionality in case of multiple origins and destinations.
5. It allows to use origin and destinations in Mappls's digital address (semicolon separated) eLoc or WGS 84 geographical coordinates both.
6. This method can only be used when CORS
is enabled on your project. For details, please contact apisupport@mappls.com.
For detailed understanding, Let’s get started!
Live Demo¶
Visit the following link for visiting the live demo:
Implementation¶
Script URL¶
<script src="https://sdk.mappls.com/map/sdk/plugins?v=3.0&access_token=<Static Key>"></script>
Method¶
mappls.getDistance()
Properties¶
Mandatory¶
coordinates
(string): Semicolon separated eloc or lat,long or both.callback
: Method to get response
Optional¶
resource
(string): Default isdistance_matrix
and can be changed todistance_matrix_eta
ordistance_matrix_traffic
as per requirement.profile
(string): Defaultdriving
for four wheelers and can be changed tobiking
andtrucking
for two wheelers and heavy vehicles respectively.-
rtype
(boolean): type of route required for navigation, where values mean:0
optimal (default)1
shortest (it will calculate route by excluding access penalties like private roads, etc.)
-
region
(string): It is for the available countries. Default is India; for other countries (Sri Lanka, Nepal, Bangladesh & Bhutan) this parameter is mandatory. Possible values areind
(for India, default),lka
(for Sri Lanka) ,npl
(for Nepal) ,bgd
(for Bangladesh),mmr
(for Myanmar) andbtn
(for Bhutan). -
sources
(string): To specify which of the coordinates/eLoc supplied are to be treated as source position for 'many to many' distance matrix calculation. The input is indicative of that coordinate/eLoc's index. E.g. 0;1 means that 0th and 1st pairs are source points. Default value is 0. The indexes must be semi-colon separated. e.g: 0;1;2;... destinations
(string): To specify which of the coordinates/eLoc supplied in the method are to be treated as destination position for 'many to many' distance matrix calculation. The input is indicative of that coordinate/eLoc's index. E.g. 2;3 means that 0th and 1st pairs are destination points. Default value is all. The indexes must be comma separated. e.g: 3;4;5;...
Example¶
mappls.getDistance({
coordinates: "mmi000;123zrr",
callback: function(data) {
console.log(data);
}
});
Sample code Snippet¶
/*CALLING DISTANCE*/
mappls.getDistance({
coordinates: "518NSV;123ZRR;28.9797,77.6763"
}, function(data) {
resdiv.innerHTML = JSON.stringify(data).replace(/{/g, '{').replace(/}/g, '}').replace(/","/g, '","');
});
IMPORTANT Note: CORS must be enabled on your credentials before accessing this method. Please contact API support (below) for enabling the same on your credentials or go to API console to enable.
That's All !
For any queries and support, please contact:
Email us at apisupport@mappls.com
Support
Need support? contact us!