嗨我在谷歌地图中有addlistener的问题 我无法从xml获得html值。总是返回[object Element]
document.getElementById("infobox").innerHTML = html;
和infowindow.setContent(html);完美地工作
我知道我在1个月之前做过这件事我不知道是v3版本还是这个版本。但我之前这样做了!
或者如果您知道获取数据的其他方式,请提供帮助!
来自addlistener中的这段代码
var side_bar_html = " ";
var html = " ";
var gmarkers = [];
var map = null;
/
function createMarker(latlng, name, html) {
var contentString = html;
var marker = new google.maps.Marker({
position: latlng,
map: map,
zIndex: Math.round(latlng.lat()*-100000)<<5,icon : 'mark.png'
});
google.maps.event.addListener(marker, 'click', function() {
document.getElementById("infobox").innerHTML = html;
infowindow.setContent(html);
infowindow.open(map,marker);
});
gmarkers.push(marker);
// add a line to the side_bar html
side_bar_html += '<a href="javascript:myclick(' + (gmarkers.length-1) + ')">' + name + '<\/a><br>';
}
function myclick(i) {
google.maps.event.trigger(gmarkers[i], "click");
}
function initialize() {
var myOptions = {
zoom: 11,
center: new google.maps.LatLng(38.06106741381199,46.359741),
mapTypeControl: true,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
// Read the data from example.xml
downloadUrl("example.xml", function(doc) {
var xmlDoc = xmlParse(doc);
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var lat = parseFloat(markers[i].getAttribute("lat"));
var lng = parseFloat(markers[i].getAttribute("lng"));
var point = new google.maps.LatLng(lat,lng);
var html = markers[i].getElementsByTagName("infowindow")[0] ;
var label = markers[i].getAttribute("label");
// create the marker
var marker = createMarker(point,label,html);
}
document.getElementById("side_bar").innerHTML = side_bar_html;
// put the assembled side_bar_html contents into the side_bar div
});
}
var infowindow = new google.maps.
InfoWindow(
{
size: new google.maps.Size(150,50)
});
xml代码:
<?xml version="1.0"?>
<maincontent>
<markers>
<marker lat="37.95989919257204" lng="46.38427734375" label="way 1">
<infowindow>station 1</infowindow>
</marker>
</markers>
</maincontent>
答案 0 :(得分:0)
我发现什么是问题只是将标签更改为属性!
var html = markers[i].getAttribute("html");
但我不知道为什么!