Closest Location
Finds the closest distance between multiple locations. Locations can be specified by an address or latitude/longitude coordinates.
Endpoint POST
https://api.ttgtoolbox.com/v1/location/route/closest
Request body
This endpoint uses the POST
method and requires a JSON object as the request body.
Required parameters
The request body requires the following parameters.
fromstringrequired
The starting address or coordinates.
tostringrequired
An array of ending address or coordinates.
Optional parameters
method
The method
parameters allows you to specify the method for the distance calculation.
method value | Examples |
---|---|
route default | driving distance |
map | straight-line "as the crow flies" |
units
Use the units
parameter to specify the units for all fields with standard units, e.g., miles or kilometers.
units value |
---|
miles default |
kilometers |
Example #1 request body
json
{
"from": "77 Massachusetts Ave, Cambridge, MA 02139",
"to": ["Annapolis, MD", "Wichita, KS", "Roswell, NM", "Ottawa, Ontario"]
}
Returns
A JSON object containing the closest distance and an array of distances between each from and to location.
Example #1 Response
json
{
"closest": {
"distance": 420.18,
"address": "Annapolis, MD"
},
"distances": [
{
"distance": 420.18,
"address": "Annapolis, MD"
},
{
"distance": 438.48,
"address": "Ottawa, Ontario"
},
{
"distance": 1623.6,
"address": "Wichita, KS"
},
{
"distance": 2159.7,
"address": "Roswell, NM"
}
]
}