How to Calculate the Length of a GeoJSON Line

API or service
Geometry Operations API
Task
LineString or MultiLineString → total length
Examples
URL
Difficulty
Beginner
Time
5 min

Calculate the length of a GeoJSON line

You have a LineString or MultiLineString representing a path, track, corridor, or boundary and need its total geodesic length. Use the Geometry Operations API length operation and choose an output unit.

Task flow: line geometry + unit → total length.

The calculation follows every segment in the submitted coordinates. It does not snap the line to roads or calculate a route; use Map Matching or Routing when the input must follow a transport network.

For a MultiLineString, the response is the combined length of all component lines.

Measure the line

This example measures one line in meters. GeoJSON positions use [longitude, latitude] order.

POST https://api.geoapify.com/v1/geometry/operation?apiKey=YOUR_API_KEY
Content-Type: application/json
{
  "operation": "length",
  "line": {
    "type": "LineString",
    "coordinates": [
      [13.38, 52.50],
      [13.44, 52.54]
    ]
  },
  "params": {
    "units": "meters"
  }
}
{
  "type": "number",
  "data": 6021.921081493014
}

The line is approximately 6,021.92 m, or 6.02 km. If params.units is omitted, the default is kilometers. Other supported physical units include miles, feet, and nauticalmiles; degrees and radians return angular rather than physical length.