# Polyline API
> Encode and decode Google/Mapbox encoded polylines — the compact ASCII string used by the Google Maps Directions API, Mapbox, Valhalla, OSRM and GPX-style route geometry to pack a list of coordinates into a few bytes. Decode an encoded string into an array of latitude/longitude points, encode a coordinate list back into a polyline (precision 5, the Google default, or 6 for OSRM/Valhalla overview), and measure a path — point count, total length by the haversine great-circle formula in km and miles, and the bounding box. Perfect for drawing routes on a map, storing tracks compactly, computing trip distance and fitting a map viewport. Pure local computation — no key, no third-party service, instant. Live, nothing stored. 4 endpoints. Distinct from coordinate-format conversion (Plus Code/MGRS/UTM) and geohash.

## Authentication
All requests require your oanor API key in the `x-oanor-key` header. Get one at https://www.oanor.com/developer/keys.

```bash
curl -H "x-oanor-key: oanor_live_…" "https://api.oanor.com/polyline-api/..."
```

## Pricing
- **Free** (Free) — 1,080 calls/Mo, 2 req/s
- **Starter** ($3/Mo) — 9,300 calls/Mo, 8 req/s
- **Pro** ($22/Mo) — 141,000 calls/Mo, 20 req/s
- **Mega** ($58/Mo) — 725,000 calls/Mo, 50 req/s

## Endpoints

### Polyline

#### `GET /v1/decode` — Decode a polyline to coordinates

**Parameters:**
- `polyline` (query, required, string) — Encoded polyline string Example: `_p~iF~ps|U_ulLnnqC_mqNvxq`@`
- `precision` (query, optional, string) — 1-12 (default 5; OSRM/Valhalla use 6) Example: `5`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/polyline-api/v1/decode?polyline=_p%7EiF%7Eps%7CU_ulLnnqC_mqNvxq%60%40&precision=5"
```

**Response:**
```json
{
    "data": {
        "precision": 5,
        "coordinates": [
            {
                "lat": 38.5,
                "lng": -120.2
            },
            {
                "lat": 40.7,
                "lng": -120.95
            },
            {
                "lat": 43.252,
                "lng": -126.453
            }
        ],
        "point_count": 3
    },
    "meta": {
        "timestamp": "2026-06-02T16:51:50.532Z",
        "request_id": "b40f7030-7f97-49e4-916a-ce839b559d4d"
    },
    "status": "ok",
    "message": "Decode an encoded polyline to coordinates",
    "success": true
}
```

#### `GET /v1/encode` — Encode coordinates to a polyline

**Parameters:**
- `coordinates` (query, required, string) — JSON array of [lat,lng] pairs Example: `[[38.5,-120.2],[40.7,-120.95],[43.252,-126.453]]`
- `precision` (query, optional, string) — 1-12 (default 5) Example: `5`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/polyline-api/v1/encode?coordinates=%5B%5B38.5%2C-120.2%5D%2C%5B40.7%2C-120.95%5D%2C%5B43.252%2C-126.453%5D%5D&precision=5"
```

**Response:**
```json
{
    "data": {
        "polyline": "_p~iF~ps|U_ulLnnqC_mqNvxq`@",
        "precision": 5,
        "point_count": 3
    },
    "meta": {
        "timestamp": "2026-06-02T16:51:50.634Z",
        "request_id": "00866047-67d0-49b0-a05c-8250f124b264"
    },
    "status": "ok",
    "message": "Encode coordinates to a polyline",
    "success": true
}
```

#### `GET /v1/info` — Path stats: points, length, bbox

**Parameters:**
- `polyline` (query, required, string) — Encoded polyline string Example: `_p~iF~ps|U_ulLnnqC_mqNvxq`@`
- `precision` (query, optional, string) — 1-12 (default 5) Example: `5`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/polyline-api/v1/info?polyline=_p%7EiF%7Eps%7CU_ulLnnqC_mqNvxq%60%40&precision=5"
```

**Response:**
```json
{
    "data": {
        "bbox": {
            "max_lat": 43.252,
            "max_lng": -120.2,
            "min_lat": 38.5,
            "min_lng": -126.453
        },
        "length_km": 788.90696,
        "precision": 5,
        "point_count": 3,
        "length_miles": 490.203907
    },
    "meta": {
        "timestamp": "2026-06-02T16:51:50.724Z",
        "request_id": "7066eb11-c588-4065-ace5-e29659fd42ef"
    },
    "status": "ok",
    "message": "Path stats for an encoded polyline",
    "success": true
}
```

### Meta

#### `GET /v1/meta` — Spec

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/polyline-api/v1/meta"
```

**Response:**
```json
{
    "data": {
        "name": "Polyline API",
        "notes": "Precision 5 is the Google Maps default; Valhalla/OSRM-overview often use 6. Pure local computation, nothing stored.",
        "version": "v1",
        "endpoints": [
            {
                "path": "/v1/decode",
                "params": {
                    "polyline": "encoded string (required)",
                    "precision": "1-12, default 5"
                },
                "returns": "array of {lat,lng}"
            },
            {
                "path": "/v1/encode",
                "params": {
                    "precision": "1-12, default 5",
                    "coordinates": "JSON array of [lat,lng] pairs (required)"
                },
                "returns": "encoded polyline string"
            },
            {
                "path": "/v1/info",
                "params": {
                    "polyline": "encoded string (required)",
                    "precision": "1-12, default 5"
                },
                "returns": "point_count, length (km+miles, haversine), bounding box"
            },
            {
                "path": "/v1/meta",
                "params": [],
                "returns": "this document"
            }
        ],
        "description": "Encode and decode Google/Mapbox encoded polylines and measure the resulting path."
    },
    "meta": {
        "timestamp": "2026-06-02T16:51:50.823Z",
        "request_id": "7173826c-6b85-4396-87ff-48fa33931dd1"
  
…(truncated, see openapi.json for full schema)
```


---
Marketplace page: https://www.oanor.com/api/polyline-api
OpenAPI spec: https://www.oanor.com/api/polyline-api/openapi.json
