Google Maps API Tutorial

© 2006, 2007 Mike Williams

 

Polylines from XML

Here's an example showing how to read polyline data from an XML file.

Here's the XML file.

The method is similar to the processing of markers from an XML file, except now each line contains several points. When the data is processed we need to use a nested loop. The outer loop steps through the lines. The inner loop steps through the points for that line.

I've put "colour" and "width" attributes in the line entries in the XML file, and used them to control the colour and width of the polylines.

It's possible to have marker and polyline information in the same XML file. The 'getElementsByTagName("marker")' bit only reads the markers and the 'getElementsByTagName("line")' bit only reads the lines.

Potential Pitfalls

  1. An XML file can only have one top level element. In the example, everything is inside the <markers> . . . </markers>. Don't try to put the markers in <markers> . . . </markers> and the lines in a separate <lines> . . . </lines> element.
     
  2. In order for VML to work, you need to use a special DOCTYPE, special <html> attributes and a special <style> entry. See this part of the official documentation.
     
  3. The potential pitfalls from Part 3 apply to polylines as well as markers

Back to Mike's Homepage
Up to the start of this tutorial