Path Length
Maps Math & Calculations Credits / request: 1Returns the total geodesic length of consecutive segments in a point list, in meters.
POST
https://api.apikodu.com/api/v1/maps/pathlength
Documentation
Overview
Length of a path (point array).
Authentication
Every request requires the x-api-key header. Credits used and remaining quota are returned in response headers (x-api-credits-used, x-api-remaining-credits, x-rate-limit-*).
Request
POST
https://api.apikodu.com/api/v1/maps/pathlength
JSON body.
Parameters
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
path |
json | * Required | — | — | At least 2 points. |
includeSegments |
boolean | Optional | true |
true false |
Segment breakdown. |
Response
| Name | Type | Description |
|---|---|---|
lengthMeters |
number | Sum of haversine segment lengths in meters. |
lengthKilometers |
number | Total length in km. lengthMeters / 1000. |
pointCount |
integer | Number of points in path. |
segmentCount |
integer | Segment count = pointCount - 1. |
segments |
array | Each segment when includeSegments=true. Empty array when false. |
segments[].index |
integer | Segment index (1-based). |
segments[].from |
object | Segment start {latitude, longitude}. |
segments[].to |
object | Segment end {latitude, longitude}. |
segments[].distanceMeters |
number | This segment's distance in meters. |
segments[].distanceKilometers |
number | This segment's distance in km. |
Errors
| HTTP | code | Description |
|---|---|---|
400 |
-234 |
path is missing or empty. |
400 |
-239 |
path must contain 2–500 points. |
400 |
-236 |
A path point has an invalid latitude/longitude. |
401 |
-100 |
x-api-key is missing, empty, malformed, inactive, banned, expired, IP-restricted, or not allowed for this API. |
429 |
-221 |
Per-minute request limit exceeded. Response headers: x-rate-limit-limit, x-rate-limit-remaining, x-rate-limit-reset. |
429 |
— | Package credit quota cannot cover this request. Body may be { error, limit, currentUsage, requestCost } (no code field). |
500 |
-1 |
Unexpected server error. message is a generic error text without technical details. |
Notes
- Success body is { data: { ... } }. Error body is { code, message }. code is an ApiResponseCode enum value (negative integer).
Sample response
{
"data": {
"lengthMeters": 3462.21,
"lengthKilometers": 3.46221,
"pointCount": 4,
"segmentCount": 3,
"segments": [
{
"index": 1,
"from": {
"latitude": 41.008,
"longitude": 28.97
},
"to": {
"latitude": 41.008,
"longitude": 28.986
},
"distanceMeters": 1342.1,
"distanceKilometers": 1.3421
},
{
"index": 2,
"from": {
"latitude": 41.008,
"longitude": 28.986
},
"to": {
"latitude": 41.015,
"longitude": 28.986
},
"distanceMeters": 778.01,
"distanceKilometers": 0.77801
},
{
"index": 3,
"from": {
"latitude": 41.015,
"longitude": 28.986
},
"to": {
"latitude": 41.015,
"longitude": 28.97
},
"distanceMeters": 1342.1,
"distanceKilometers": 1.3421
}
]
}
}
Code samples
const response = await fetch('https://api.apikodu.com/api/v1/maps/pathlength', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'YOUR_API_KEY'
},
body: JSON.stringify({
name: 'example',
value: 123
})
});
const data = await response.json();
console.log(data);
import requests
headers = {
'Content-Type': 'application/json',
'x-api-key': 'YOUR_API_KEY'
}
payload = {
'name': 'example',
'value': 123
}
response = requests.post('https://api.apikodu.com/api/v1/maps/pathlength', headers=headers, json=payload)
data = response.json()
print(data)
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("x-api-key", "YOUR_API_KEY");
var payload = new { name = "example", value = 123 };
var json = JsonSerializer.Serialize(payload);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.apikodu.com/api/v1/maps/pathlength", content);
response.EnsureSuccessStatusCode();
var data = await response.Content.ReadAsStringAsync();
Console.WriteLine(data);
$data = [
'name' => 'example',
'value' => 123
];
$response = file_get_contents('https://api.apikodu.com/api/v1/maps/pathlength', false, stream_context_create([
'http' => [
'header' => "x-api-key: YOUR_API_KEY"
],
'method' => 'POST',"
'content' => json_encode($data)
]));
print_r(json_decode($response, true));
curl -X POST 'https://api.apikodu.com/api/v1/maps/pathlength' \
-H 'Content-Type: application/json' \
-H 'x-api-key: YOUR_API_KEY' \
-d '{
"name": "example",
"value": 123
}'
Start building in minutes
Create a free account, get your API key and send your first request in minutes.