Locate Service: Locate Calculate Routes API
This api service allows you to calculate distance and time travel (assumption that mode is by car) from an origin to a destination.
Request Body: JSON
{
"service": "locate-calculate-routes",
"payload": {
"origin": {
"longitude": 121.03643119603505,
"latitude": 14.564836491173898
},
"destinations": [
{
"id": "alabang_town_center",
"longitude": 121.02987882350594,
"latitude": 14.423275009087039
},
{
"id": "glorietta3",
"longitude": 121.02520692350924,
"latitude": 14.552416494027579
}
],
"distance_unit": "Kilometers"
}
}
Request Body Definition
- service - This defines the service that we want to use
- payload - Information needed in order for the service to process the request
- payload.origin - A dictionary having the longitude and latitude keys of the place of origin.
- payload.destinations - A list of dictionaries where each object is the destination to be calculated from the origin place. Please note that since it allows multiple destinations to be calculated from the origin, each destination will be calculated as 1 credit consumed. Each object must have the following:
- id - a unique identifier for each place object
- longitude - the longitude of the place object
- latitude - the latitude of the place object
- payload.distance_unit - A string specifying what units to use for the results. Valid values are Kilometers or Miles.
Sample Response
If your request is successful, you will receive the following response where you get the result and the credits you have left after making the request, with a status code of 200.
{
"result": {
"calculations": [
{
"id": "alabang_town_center",
"coordinates": {
"longitude": 121.02987882350594,
"latitude": 14.423275009087039
},
"distance": 20.008,
"travel_seconds": 1905
},
{
"id": "glorietta3",
"coordinates": {
"longitude": 121.02520692350924,
"latitude": 14.552416494027579
},
"distance": 2.82,
"travel_seconds": 556
}
],
"distance_unit": "Kilometers"
},
"remaining_credits": 804
}
If your request is not successful, you will receive a message from the json response describing the error. Possible errors may be due to:
- Invalid API token with status code 401
- Invalid service name with status code of 422
- Not enough credits with status code of 422
- Invalid payload with status code of 422
Response Data Definition
- result - A dictionary containing the calculations for each destination.
- remaining_credits - The remaining locate credits after calling the api service.