Hey everyone! Sorry for the delay in posting this. It's been a busy time lately. I'm spending half my time in
This example I use the following method to plot my points.
- All addresses are already geocoded in my clients.xml file - (See part one to see how I mass geocoded the addresses to get them in there.)
- Use GDownloadUrl to open clients.xml via AJAX
- Loop over each entry and add to map
Ok so our clients.xml file should look something like this (I'm just posting a few lines).
<marker address="
Easy enough, got the address and the cords that's all we need. Note: Again I am guilty for not putting enough information, I really should have put the persons name, etc.
GDownloadUrl - from XML to our Map
Here is the relevant code that we'll be looking at. We use the Google function GDownloadUrl to open our XML file. The output is directly passed to the adjorning function with the variable 'doc'. We then use GXml to parse the downloaded file 'doc', that is saved as xmlDoc. We then read the elements named 'marker' which is in this case our entire file, that is saved as 'marker'.
var xmlDoc = GXml.parse(doc);var markers = xmlDoc.documentElement.getElementsByTagName("marker");
Loop It
We now do a loop over all the markers returned. This will loop over every address we have geocoded. You can see we use getAttribute to extract the latitude and longitude values from the markers. They are extracted then saved to point using the GLatLng function. You can see also I extract the attribute for 'html' and 'label'. In my example I never put any values into these attributes. I would recommend that you do so. You could put in the persons name or whatever information you need.
// obtain the attribues of each marker
var label = markers[i].getAttribute("label");
So really that's it! The hard work of geocoding was already done in my last example, then I saved it to XML, now this map just loops over the XML file and displays it. If anyone has any questions about pretty much anything relating to Google's Map API please post a comment. In the future I'll do more tutorials and probably some videos.
Here is this example live so you can see it work and view the full source.
Stumble It