Polyline Encoder / Decoder

Encode coordinates into a Google polyline string or decode one back to lat/lng and GeoJSON, right in your browser. Your route stays on your device.

The coordinates and polyline strings you paste are encoded and decoded locally in your browser and are never uploaded; nothing you enter is stored on a server.

Built and maintained by Udit Agarwal

Want to see the route on a map? Open the Coordinate Map Viewer.

About Polyline Encoder & Decoder

This polyline encoder and decoder handles Google's Encoded Polyline Algorithm Format entirely in your browser. In Encode mode, paste one "lat, lng" per line — or a GeoJSON LineString — and get the compact encoded string that Directions APIs return for a route. In Decode mode, paste an encoded polyline and read back the coordinate list plus a ready-to-use GeoJSON LineString you can drop into a map. A precision toggle switches between 5 (the Google Maps default) and 6 (used by OSRM, Valhalla and Mapbox), which is the usual reason a decoded route lands in the wrong place. Polylines pack a whole path into a short ASCII string, so this is handy when an API hands you an encoded route and you need plain coordinates, or vice versa. Everything is computed on your device and the route you paste is never uploaded.

Features

  • Encode a list of lat/lng coordinates into a Google Encoded Polyline string
  • Decode a polyline back to coordinates and an equivalent GeoJSON LineString
  • Toggle precision 5 (Google Maps) or 6 (OSRM, Valhalla, Mapbox) for both directions
  • Accepts "lat, lng" per line, or a GeoJSON LineString / Feature as encode input
  • Emits a GeoJSON LineString you can paste straight into a map or geojson.io
  • Flags a wrong-precision decode, the classic cause of a route landing off by ~10x
  • Copy the encoded string, the coordinate list, or the GeoJSON with one click
  • Load a canonical example to see the format before pasting your own route

How to use the Polyline Encoder & Decoder

  1. Choose Encode to turn coordinates into a polyline, or Decode to expand one.
  2. Pick precision 5 (Google) or 6 (OSRM/Valhalla) to match your data source.
  3. Paste coordinates (one "lat, lng" per line or a GeoJSON LineString), or an encoded polyline.
  4. Read the encoded string, or the coordinate list and GeoJSON LineString, in the results.
  5. Copy any output for your map, API request, or data file.

Example

Input

38.5, -120.2
40.7, -120.95
43.252, -126.453

Output

_p~iF~ps|U_ulLnnqC_mqNvxq`@

The canonical three-point route from Google's docs, encoded at precision 5.

Common errors & troubleshooting

  • A decoded route is offset or scaled about ten times too far. — The precision is mismatched. Google and Google Maps use 5; OSRM, Valhalla and Mapbox use 6. Switch the precision toggle to match whatever produced the string.
  • The decoded points look plausible but the map draws the line in the sea. — Polylines and this tool store latitude first, but GeoJSON positions are [longitude, latitude]. Use the GeoJSON output as-is rather than swapping the pairs yourself.
  • Decoding stops with a "malformed polyline" message. — The string was truncated or copied with extra characters. Copy the whole polyline, and remove any surrounding quotes or JSON escaping such as a doubled backslash.

Frequently asked questions

What is a Google encoded polyline?
It is a compact ASCII encoding of a path of latitude/longitude points, defined by Google's Encoded Polyline Algorithm Format. Directions and Roads APIs return routes this way because the string is far shorter than a full list of coordinates, and it decodes back to the exact points.
Should I use precision 5 or 6 for my polyline?
Use 5 for Google Maps and the Google Directions API, and 6 for OSRM, Valhalla, GraphHopper and Mapbox. Precision 6 keeps one extra decimal, so a string encoded at 6 but decoded at 5 lands roughly ten times off — always match the tool that created the polyline.
How do I convert an encoded polyline to GeoJSON?
Switch to Decode, paste the polyline, and the tool outputs a GeoJSON LineString Feature alongside the plain coordinate list. The GeoJSON already uses [longitude, latitude] order, so you can paste it straight into geojson.io, Leaflet or a mapping library.
Can I encode a GeoJSON LineString into a polyline?
Yes. In Encode mode you can paste a GeoJSON LineString, or a Feature or FeatureCollection wrapping one, and the tool reads its coordinates and returns the encoded string. You can also paste plain "lat, lng" lines if you do not have GeoJSON.
Is my route data sent anywhere when I encode or decode it?
No. The encoding and decoding run entirely in your browser using the standard algorithm, so the coordinates and polylines you paste are processed on your device and are never uploaded to a server.

Related tools

  • GeoJSON Viewer & Validator — Paste or drop GeoJSON to validate it and see its features on a map, with feature counts and a bounding box.
  • GPX to GeoJSON — Convert GPX to GeoJSON and back — GPS tracks, routes and waypoints to GeoJSON features, or GeoJSON back to a GPX file.
  • Coordinate Converter (DMS & Decimal) — Convert coordinates between decimal degrees, DMS and degrees-decimal-minutes, both ways, in your browser.
  • Coordinate Map Viewer — Plot a latitude/longitude on an OpenStreetMap map, or click the map to read coordinates back out.
  • GeoJSON to CSV — Convert a GeoJSON FeatureCollection to CSV and back — Point features become latitude/longitude columns with their properties.
  • WKT to GeoJSON — Convert WKT (Well-Known Text) to GeoJSON and back, in your browser.

Guides

More Geo / Maps tools

  • GeoJSON Viewer & Validator — Paste or drop GeoJSON to validate it and see its features on a map, with feature counts and a bounding box.
  • UTM Converter — Convert between latitude/longitude and UTM coordinates (zone, hemisphere, easting, northing) on the WGS84 ellipsoid.
  • GeoJSON Bounding Box — Get the bounding box, centre, area and length of any GeoJSON, in both coordinate orders.
  • GeoJSON Simplify — Thin dense GeoJSON lines and polygons with Douglas–Peucker at a metre tolerance.
  • Map Tile Calculator — Convert between coordinates, XYZ tiles, TMS and quadkeys, with tile counts.
  • NMEA Parser — Decode GPS NMEA sentences into coordinates, speed and GeoJSON, checksums included.
  • Maidenhead Grid Square Converter — Convert coordinates to a Maidenhead locator and back, with distance and beam heading.
  • Geographic Midpoint Calculator — Find the true midpoint of two or more coordinates, with optional weights.
  • Point in Polygon Checker — Test whether coordinates fall inside a GeoJSON polygon, with holes handled.
  • Web Mercator Converter — Convert WGS84 latitude and longitude to EPSG:3857 metres, and back.
  • Country Code Lookup — Search ISO 3166-1 alpha-2, alpha-3, numeric, dialling codes and ccTLDs.
  • Coordinate Map Viewer — Plot a latitude/longitude on an OpenStreetMap map, or click the map to read coordinates back out.

See all Geo / Maps tools (23) · All tools