Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

Chapter 9 — Using Overlays 155


}
}
}
request.send(null);
}
}


The basic process is as listed earlier — the page is loaded, and during the onLoad()function
the JavaScript requests the XML, loads it, parses the contents, and then generates the markers.
The addmarker()function does not change; it doesn’t need to.


You can see the results in Figure 9-2. The basic operation of the map has not changed; no
additional information is being shown and, in reality, there is no interactivity built into the
map, but the information that is generated is now more dynamic. Changing the XML (rather
than the HTML) would change the information shown on the map.


FIGURE9-2: Generating a map by dynamically loading XML.


Always make sure that any numerical information that you load into JavaScript for use with your
map, particularly when specifying latitude or longitude, is first parsed with the parseFloat()
function (or parseInt()) to ensure that the string is correctly identified as a number.

Free download pdf