I’m almost sure this question has been asked before, but for the love of me I just can’t find the answer anywhere. Basically what I want to do is create multiple markers on a custom Google Map I’m building. I already have an XML file with the coordinates (lat/lng) and title of each item. I’d like to take the data from the XML file and use it to create markers on the map. I’ve found how to do this using KML files and MySQL/PHP, but I need to know how to do it in Javascript.
One more thing: I have a .xml file of my own, so it won’t be like I’ll be getting the data from a webpage because I believe (from research I’ve done today) that the code for that may be different.
If anyone knows if this has been posted somewhere else before, could you please direct me there? I’ve literally been searching all day, this is my last resort. Thanks a ton!!!
If you are looking for a way to parse xml text in JavaScript, then look here:
XML parsing of a variable string in JavaScript
Info about loading xml file from JavaScript here:
Load xml from javascript
Creating markers from custom xml is then quite simple. I added a short example. It shows how to parse xml text or load xml file and then create markers from the data.
Some custom xml text:
Parsing the xml text into xml DOM object:
Loading and parsing a xml file into xml DOM object:
Create the markers from data in xml DOM object:
To create the markers from xml file, all you need to do is:
To create the markers from the xml text, use: