Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!



GLineEnc is a Google Maps Polyline Encoder--it encodes line geometries such that they can be rendered more efficiently in the browser.

The encoding algorithm is described here:


GLineEnc is packaged as a standard distutils distribution. It can be installed via easy_install, pip, python install, or by adding it to the install_requires list in your For example:

pip install glineenc


GLineEnc exposes a single API function, encode_pairs. This function accepts a sequence of latitude/longitude pairs and returns a string representing the encoded points and another string indicating the maximum zoom level at which each point should be displayed:

>>> from glineenc import encode_pairs
>>> result = encode_pairs([(38.5, -120.2), (43.252, -126.453)])
>>> result
('_p~iF~ps|U_c_\\fhde@', 'BB')

You could JSONify the result like this to pass it to the browser:

>>> import json
>>> json.dumps({'points': result[0], 'levels': result[1]})
'{"points": "_p~iF~ps|U_c_\\\\fhde@", "levels": "BB"}'

On the client, you would create a line from this encoded data like so:

// It's assumed here that you've decoded the JSON object created
// above into a local var named `result`.
var path = google.maps.geometry.encoding.decodePath(result.points);
var myLine = new google.maps.Polyline({path: path});

In Google Maps v2, that would look like this instead:

var myLine = new GPolyline.fromEncoded({
    points: result.points,
    levels: result.levels

Recent activity

Wyatt Baldwin

Commits by Wyatt Baldwin were pushed to wyatt/glineenc

256ee3c - Update .hgignore as discussed in pull request 1 Mainly, this involved making sure certain rules only match at the root of the repo. I also ...
Wyatt Baldwin

Commits by Wyatt Baldwin were pushed to wyatt/glineenc

7cb607b - Convert tests to unittest.TestCase So we can run tests easily via `python -m unittest discover .`
Wyatt Baldwin

Commits by Wyatt Baldwin were pushed to wyatt/glineenc

a15564b - Merge reorganize_package branch with a few tweaks - Move tests package into glineenc package - Use packages option instead of py_modules in setup() - Export ...
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.