Example encoded polylines
Here are a few examples to illustrate the basic use of encoded polylines.
- Example 1
A basic encoded polyline with about 700 points. This is
exactly the example generated by the "set example" button
above with the default parameters.
- Example 2
The same polyline but using the parameters verySmall=0.00008,
numLevels=9, and zoomFactor=4. This allows you to see the
changes as you zoom in and out.
- The coast of Britain
About 50,000 points approximating the coast of Britain. This was
generated by the form, but I had to hit the continue script button
in firefox a couple of times to complete the encoding process.
Also, only part of the code for the
polyline seemed to appear in the form. After I hit select all and
copied and pasted into a good text editor, the entire code was there.
- A fractal example
This is a somewhat artificial, but very cool example of a fractal
path with nearly 400,000 points. It might take a moment to load,
since the javascript file is over 1M, even with encoding.
I need to hit the continue script button once on my Macbook Pro
running Firefox at 2.3 GHz, but it runs quite smoothly after that.
Here are a few examples to illustrate how encoding affects the
performance of a polyline. All four examples display the same line
with about 9700 points from LA to NY obtained from a Google Map
directions search. Using most browsers, you can also turn SVG on or
off in the first two examples. (SVG, or Scalable Vector Graphics, is
a file type for storing images. Many browsers display polylines using
SVG by default, with the notable exception of Internet Explorer. SVG
is very efficient and will also improve the performance of polylines,
encoded or not.) Of course, in Internet Explorer, you're stuck with
VML.
- A properly encoded polyline
This should work fairly smoothly with or without SVG.
- A normal polyline
This will probably work with SVG, although you will likely notice
a serious degradation of performance from the previous example.
It will probably not work without SVG.
- Encoding by GGeoXml
The API function GGeoXml is one way to encode via the API. While
very nice, this doesn't offer quite as much performance benefit as
pre-encoding the line.
- An improperly encoded polyline
Warning: This will likely crash your browser!
As we will see, encoding a polyline can be tricky. Choosing the
levels string (described below) incorrectly can lead to even worse
performance than a regular polyline. In fact, this example is unlikely
to work, even with SVG!