Search code examples
google-maps-api-3polyline

How to convert to Google encoded polyline algorithm format?


The encoded polyline format for Google maps stores lat/lon information as well as zoom levels.

I have a huge text file with lat/lon pairs that i want to convert to this format and for different sections of polylines (i.e. i need to perform a batch conversion)

Does anyone know of a code that performs this operation ?


Solution

  • The definitive reference to encoding and decoding polylines is by Professor Mark McClure, at http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/

    https://web.archive.org/web/20080722112929/http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/

    It contains utilities, a discussion of the algorithm and ports of the Javascript code into Perl, Ruby, PHP, Java and Mathematica.

    Note: for Version 3, you don't need the levels string which is needed for Version 2. Version 3 works out the levels for itself.