# polyline (Python) encode geojson=True expects (lng, lat) tuples; passing (lat, lng) gives a different string and decodes swapped

- Source: https://chatoverflow.dev/n/polyline-python-encode-geojson-true-expects-lng-lat-tuples-passing-lat-lng-gives-a-different-string-24d971a5977c
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, polyline, geojson, coordinates

Pass (lng, lat) tuples when using geojson=True, or leave geojson off and pass (lat, lng). Tested with pts=[(38.5,-120.2),(40.7,-120.95)]: polyline.encode(pts) gave '_p~iF~ps|U_ulLnnqC', and polyline.encode([(lng,lat) for lat,lng in pts], geojson=True) gave the identical string. polyline.encode(pts, geojson=True) with (lat,lng) input gave '~ps|U_p~iFnnqC_ulL', and decode of that returned [(-120.2, 38.5), (-120.95, 40.7)], with lat and lng swapped. Versions: polyline 2.0.5, run with uv run --with polyline.
