aaronantrim
Technical User
- Apr 7, 2008
- 5
Hi,
I'm doing a little bit of Google Maps API work and am new to JavaScript.
Here is the code:
Everything is working fine, except that instead of string values for the names of bus stops taken from an XML file being displayed in an HTML list, I the text [object Element] comes back, like this:
I find this peculiar, because when I pass stop_name earlier (var stop_marker = createMarker(point,stop_name)), the expected text is displayed as I would expect.
If more context will be helpful to get your mind around this problem, here is an excerpt from the XML file:
Anything you can offer will be a great help. Thanks!
I'm doing a little bit of Google Maps API work and am new to JavaScript.
Here is the code:
Code:
// load the XML file
var request = GXmlHttp.create();
request.open("GET", "stops.xml", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {var xmlDoc = request.responseXML;
// make objects for the three elements of the XML file
var points = xmlDoc.documentElement.getElementsByTagName("point");
var icons = xmlDoc.documentElement.getElementsByTagName("icon");
var name = xmlDoc.documentElement.getElementsByTagName("name");
// loop over all the stops in stops.xml
for (var i = 0; i < points.length; i++) {
// create lat & long point
var point = new GPoint(parseFloat(points[i].getAttribute("lng")), parseFloat(points[i].getAttribute("lat")));
// set the name of the stop
stop_name=name[i];
// create marker and place on the map
var stop_marker = createMarker(point,stop_name)
map.addOverlay(stop_marker);
// now, create HTML that shows a text list of stops with links the trigger a javascript function that opens an info window
listofstops=document.getElementById('listofstops');
listofstops.innerHTML=listofstops.innerHTML += '<a href="javascript:myclick(' + i + ')">' + stop_name + '</a><br>';
}
}
}
Everything is working fine, except that instead of string values for the names of bus stops taken from an XML file being displayed in an HTML list, I the text [object Element] comes back, like this:
Code:
<a href="javascript:myclick(15)">
[object Element]
</a>
I find this peculiar, because when I pass stop_name earlier (var stop_marker = createMarker(point,stop_name)), the expected text is displayed as I would expect.
If more context will be helpful to get your mind around this problem, here is an excerpt from the XML file:
Code:
<stops>
<stop>
<name>Metro Center</name>
<point lng="-112.1233070252521" lat="33.57291578875893"/>
<icon image="vm-logo.png" class="local"/>
</stop>
Anything you can offer will be a great help. Thanks!