# Static map images

> Render a PNG or WebP map of a route with numbered stops, up to 1280x1280 at @2x, from OpenStreetMap data. curl, Python and Dart examples.

Source: https://www.wayline.cloud/docs/guides/static-maps

`/v1/staticmap` returns a ready-to-display image of a route and its stops: one HTTPS call, no map SDK. It is built for reports, emails, PDFs and list screens, for example "where did this rep ride today".

- PNG (default), JPEG or WebP, up to **1280 x 1280**, with `scale=2` for retina screens. A `1280x800` map at `scale=2` is 2560 x 1600 px, sharp enough to zoom 2 to 4 times in an app.
- Paths from an **encoded polyline** (precision 5 or 6), so `routes[0].geometry` from [`/v1/route`](/docs/api) goes in unchanged.
- **Numbered markers** (1 to 999), start and end styles, colors and letters.
- The view fits all paths and markers automatically, or you set `center` and `zoom`.
- The base map is drawn from OpenStreetMap, with street names readable in Dhaka at zoom 15 to 16.
- **"© OpenStreetMap contributors" is drawn on every image** (bottom-right), so you meet the ODbL attribution requirement without adding anything.

## 1. Get the road path for the day

Ask `/v1/route` for the day's stops in order. `overview=simplified` keeps the polyline short enough for a GET URL. Use `full` (the default) with POST when you want every bend.

```bash
curl -G https://api.wayline.cloud/v1/route \
  -H "Authorization: Bearer $WAYLINE_KEY" \
  --data-urlencode "origin=23.7465,90.3760" \
  --data-urlencode "waypoints=23.7509,90.3935|23.7590,90.3890|23.7640,90.3790" \
  --data-urlencode "destination=23.7781,90.3795" \
  -d profile=motorcycle -d overview=simplified
```

`routes[0].geometry` is an encoded polyline (precision 5). Pass `geometry=polyline6` for precision 6 and add `precision:6` to the path below.

## 2. Draw it: GET

```bash
curl -G https://api.wayline.cloud/v1/staticmap \
  -H "Authorization: Bearer $WAYLINE_KEY" \
  -d size=1280x800 -d scale=2 \
  --data-urlencode "path=color:0x2563eb|weight:5|enc:$POLYLINE" \
  --data-urlencode "markers=style:start|label:1|23.7465,90.3760" \
  --data-urlencode "markers=numbered:2|23.7509,90.3935|23.7590,90.3890|23.7640,90.3790" \
  --data-urlencode "markers=style:end|label:5|23.7781,90.3795" \
  -o day.png
```

| Parameter | Values |
| --- | --- |
| `size` | `WIDTHxHEIGHT`, each 64 to 1280 (default `600x400`). Or `width` and `height`. |
| `scale` | `1` or `2` |
| `format` | `png` (default, lossless), `jpg` (about 5x smaller: best for app and web previews) or `webp` (lossless) |
| `padding` | Pixels kept clear around the fitted content (default 48) |
| `center`, `zoom` | Set both to fix the view (zoom 0 to 18); omit both to fit |
| `path` | Repeatable, up to 10. `color:`, `weight:` (1 to 20), `opacity:` (0 to 1), `precision:5\|6`, then `enc:<polyline>` **last**, or a list of `lat,lng` points |
| `markers` | Repeatable, up to 100 markers. `style:default\|start\|end\|dot`, `color:`, `label:` (up to 3 letters or digits), `numbered:N` to number the points N, N+1, … |

Colors: `0xRRGGBB`, `0xRRGGBBAA`, `#RRGGBB` or `blue`, `red`, `green`, `black`, `white`, `gray`, `orange`, `purple`, `yellow`, `teal`. Start markers are green, end markers red, others blue unless you set `color`.

A 30-stop day with a simplified route makes a URL of roughly 3 to 8 KB. Keep GET URLs under **16 KB**; beyond that, POST.

## 3. Draw it: POST (long paths)

The JSON body takes the route geometry exactly as `/v1/route` returned it (up to 2 MB, 25,000 points over all paths).

```bash
curl https://api.wayline.cloud/v1/staticmap \
  -H "Authorization: Bearer $WAYLINE_KEY" -H "Content-Type: application/json" \
  -d '{
    "width": 1280, "height": 800, "scale": 2,
    "paths": [{"polyline": "'"$POLYLINE"'", "precision": 5, "color": "#2563eb", "width": 5}],
    "markers": [
      {"lat": 23.7465, "lng": 90.3760, "label": "1", "style": "start"},
      {"lat": 23.7509, "lng": 90.3935, "label": "2"},
      {"lat": 23.7781, "lng": 90.3795, "label": "3", "style": "end"}
    ]
  }' -o day.png
```

### Python

```python
import os, requests

API = "https://api.wayline.cloud"
H = {"Authorization": f"Bearer {os.environ['WAYLINE_KEY']}"}
stops = [(23.7465, 90.3760), (23.7509, 90.3935), (23.7590, 90.3890), (23.7640, 90.3790), (23.7781, 90.3795)]

route = requests.post(f"{API}/v1/route", headers=H, json={
    "origin": {"lat": stops[0][0], "lng": stops[0][1]},
    "destination": {"lat": stops[-1][0], "lng": stops[-1][1]},
    "waypoints": [{"lat": a, "lng": b} for a, b in stops[1:-1]],
    "profile": "motorcycle",
}, timeout=10).json()

markers = [{"lat": a, "lng": b, "label": str(i + 1)} for i, (a, b) in enumerate(stops)]
markers[0]["style"], markers[-1]["style"] = "start", "end"

img = requests.post(f"{API}/v1/staticmap", headers=H, json={
    "width": 1280, "height": 800, "scale": 2,
    "paths": [{"polyline": route["routes"][0]["geometry"], "width": 5}],
    "markers": markers,
}, timeout=20)
img.raise_for_status()
open("day.png", "wb").write(img.content)
```

### Dart (server-side, `package:http`)

```dart
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;

Future<void> main() async {
  final key = Platform.environment['WAYLINE_KEY']!;
  final headers = {'Authorization': 'Bearer $key', 'Content-Type': 'application/json'};
  final stops = [[23.7465, 90.3760], [23.7509, 90.3935], [23.7781, 90.3795]];

  final route = jsonDecode((await http.post(
    Uri.parse('https://api.wayline.cloud/v1/route'),
    headers: headers,
    body: jsonEncode({
      'origin': {'lat': stops.first[0], 'lng': stops.first[1]},
      'destination': {'lat': stops.last[0], 'lng': stops.last[1]},
      'waypoints': [for (final s in stops.sublist(1, stops.length - 1)) {'lat': s[0], 'lng': s[1]}],
      'profile': 'motorcycle',
    }),
  )).body);

  final res = await http.post(
    Uri.parse('https://api.wayline.cloud/v1/staticmap'),
    headers: headers,
    body: jsonEncode({
      'width': 1280, 'height': 800, 'scale': 2,
      'paths': [{'polyline': route['routes'][0]['geometry']}],
      'markers': [
        for (var i = 0; i < stops.length; i++)
          {'lat': stops[i][0], 'lng': stops[i][1], 'label': '${i + 1}',
           'style': i == 0 ? 'start' : (i == stops.length - 1 ? 'end' : 'default')},
      ],
    }),
  );
  if (res.statusCode != 200) throw Exception(res.body);
  await File('day.png').writeAsBytes(res.bodyBytes);
}
```

For a list or feed in an app, request `format=jpg` (a 1280x800 @2x day map is roughly 0.5 MB instead of 3 MB as PNG). Keep the key on your server: render the image there, store it (or its URL) with the report, and send that to the app. To zoom from 1x to 4x in Flutter, show the stored image in an `InteractiveViewer`.

## Response headers

| Header | Meaning |
| --- | --- |
| `Content-Type` | `image/png`, `image/jpeg` or `image/webp` |
| `X-Map-Zoom`, `X-Map-Center` | The view used (fitted or given) |
| `X-Cache` | `HIT` when served from the server-side image cache |
| `X-Units-Charged` | Always `1` |

Errors return the usual [JSON error envelope](/docs/errors) with a `field`, for example `{"code":"INVALID_REQUEST","field":"path[0]","message":"Invalid request: malformed encoded polyline."}`. A view whose points are all outside coverage returns `OUT_OF_COVERAGE`.

## Billing and caching

- **One `static_map` unit per image** that returns HTTP 200. Errors are never billed.
- Rendered images are cached on our servers for one hour, keyed by a hash of every parameter. **A cached image is billed the same as a fresh one**, like every other Wayline endpoint: the price does not depend on our cache, so your bill is predictable. Store the image on your side if you show it repeatedly.
- See the per-1,000 price on the [pricing page](/pricing). Usage appears in the dashboard as **Static map images**.

## Coverage

Static maps are available where a region has map tiles, starting with Bangladesh. The map data date is on the [Coverage page](/coverage). Map data © [OpenStreetMap contributors](https://www.openstreetmap.org/copyright).
