Calculate Distance
Calculates the travels or straight-line distance between two locations. Location can be specified by an address or latitude/longitude coordinates.
Endpoint POST
https://api.ttgtoolbox.com/v1/location/route/distance
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
The 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": "42.3592,-71.04928"
}
Example #2 request body with optional parameters
json
{
"from": "Kitch-iti-Kipi, Michigan",
"to": "Kalamazoo, MI",
"units": "kilometers"
}
Example #1 Response
json
{
"distance": 3.13
}