Skip to content

Instantly share code, notes, and snippets.

@fitnr
Created October 20, 2015 18:55
Show Gist options
  • Select an option

  • Save fitnr/53eb580cbe8d78f56585 to your computer and use it in GitHub Desktop.

Select an option

Save fitnr/53eb580cbe8d78f56585 to your computer and use it in GitHub Desktop.
Quick cli tool for encoding coordinates with Google's encoded polyline algorithm. Requires polyencode (pip install polyencode).
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import gpolyencode
"""
polyencode.py
Encode list of x,y coordinates with Google's encoded polyline algorithm
see: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
usage: python polyencode.py -72,41.9 -73,42.0 -74,42.1 -75,42.3
:returns string
"""
points = [(float(x), float(y)) for x, y in [point.split(',') for point in sys.argv[1:]]]
print gpolyencode.GPolyEncoder().encode(points).get('points')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment