<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Wyatt Baldwin &#187; planet python</title>
	<atom:link href="http://wyattbaldwin.com/tag/planet-python/feed/" rel="self" type="application/rss+xml" />
	<link>http://wyattbaldwin.com</link>
	<description></description>
	<lastBuildDate>Tue, 20 Jul 2010 17:43:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Google Maps Encoded Polylines</title>
		<link>http://wyattbaldwin.com/2007/04/19/google-maps-encoded-polylines/</link>
		<comments>http://wyattbaldwin.com/2007/04/19/google-maps-encoded-polylines/#comments</comments>
		<pubDate>Thu, 19 Apr 2007 15:19:03 +0000</pubDate>
		<dc:creator>Wyatt</dc:creator>
				<category><![CDATA[planet python]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://wyattbaldwin.com/2007/04/19/google-maps-encoded-polylines/</guid>
		<description><![CDATA[Update 6/30/07: Fixed links to glineenc.py so that it’s actually accessible. Update 7/15/08: Fixed links to glineenc.py again because of change to HTTPS on Trac site. Here’s some Python code (complete with unit and doc tests) for converting a series &#8230; <a href="http://wyattbaldwin.com/2007/04/19/google-maps-encoded-polylines/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>Update 6/30/07: Fixed links to glineenc.py so that it’s actually accessible.</em><br />
<em>Update 7/15/08: Fixed links to glineenc.py again because of change to HTTPS on Trac site.</em></p>
<p><a href="http://project.bycycle.org/browser/spinoffs/glineenc.py">Here’s some Python code</a> (complete with unit and doc tests) for converting a series of latitude/longitude points (i.e., a polyline) to the Base64 encoding that Google Maps understands. It’s particularly useful for long and/or complicated lines.</p>
<p>It’s based on the algorithm listed <a href="http://www.google.com/apis/maps/documentation/polylinealgorithm.html">here</a> and the JavaScript code <span style="text-decoration: line-through;"><a href="http://www.google.com/apis/maps/documentation/polyline.js">here</a></span> [page disappeared].</p>
<p><a href="http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/">This site</a> gives some more insight into it and has a pretty cool example of a fractal line <a href="http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/fractalLog5Log4.html">here</a>.</p>
<p>Here’s the code:</p>
<p><em>Previously, I had pasted the Python code right into this article, but I recently made a bunch of revisions and it was way too long. Here’s a link to the code instead:</em></p>
<p><a href="http://project.bycycle.org/browser/spinoffs/glineenc.py">glineenc.py on Trac</a></p>
<p>Please note that this code is still in somewhat of a rough state. I have plans to polish and package it up, but for now, I’m <a href="http://bycycle.org/">using it</a> as is and it’s <a href="http://bycycle.org/regions/portlandor/routes;find?s=longitude%3D-123.42041%2C%20latitude%3D45.769439&amp;e=longitude%3D-121.786194%2C%20latitude%3D44.957024&amp;pref=default">working quite well</a> (you’ll have to be patient to click that link as it takes ~20-30 seconds to generate the route, even though the line drawing itself is almost instantaneous).</p>
<p>JavaScript that uses results from `glineenc` looks something like this (assuming you’ve returned some <span class="caps">JSON</span>, say, with `encoded_points` and `encoded_lines` keys):</p>
<pre><code>
map.addOverlay(new GPolyline.fromEncoded({
  color: "#0000ff",
  weight: 4,
  opacity: 0.8,
  points: result.encoded_points,
  levels: result.encoded_levels,
  zoomFactor: 32,
  numLevels: 4
}));
</code></pre>
<p>`points` is the encoded lat/long points. `levels` indicates which zoom levels each point should displayed at; there is one character per point. See the links above for a more complete explanation.</p>
]]></content:encoded>
			<wfw:commentRss>http://wyattbaldwin.com/2007/04/19/google-maps-encoded-polylines/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
