我一直在阅读stackoverflow的其他条目,但我真的无法理解它是如何工作的:
for(a in elements){
var address = elements[a].location;
var contentString = '<table>';
for(b in elements[a].other_fields){
var current = elements[a].other_fields[b];
switch(current.type){
case "text":
contentString += "<tr><td class = 'the_title'>" + current.label + ":</td><td class = 'the_value'>" + current.values[0].value + "</td></tr>";
break;
case "date":
if(!current.values[0].end){
var end_date_output_string = "";
}else{
var end_date_output_string = " -> " + current.values[0].end;
}
contentString += "<tr><td class = 'the_title'>" + current.label + ":</td><td class = 'the_value'>" + current.values[0].start + end_date_output_string + "</td></tr>";
break;
}
}
contentString += "</table>";
contentString += "<input type = 'button' onclick = 'window.open(\"" + elements[a].url + "\");' value = 'Open in Podio'>";
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
alert(contentString);
addMarker(results[0].geometry.location);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
//open_info_window(a, contentString);
}
function addMarker(location) {
var marker_copy = new google.maps.Marker({
position: location,
map: map
});
marker = marker_copy;
markersArray.push({
"marker": marker,
"info_window": null
});
alert("marker added: " + markersArray.lenght);
}
// Opens info windows
function open_info_window(key, contentString) {
var infowindow = new google.maps.InfoWindow({
content: contentString
});
alert(key);
markersArray[key].info_window = infowindow;
google.maps.event.addListener(markersArray[key].marker, "click", function() {
markersArray[key].info_window.open(map, markersArray[key].marker);
});
}
我尝试提醒(contentString)的部分不会提醒我所期望的,这与闭包有关,但实际上我以前从未遇到过这样的代码。任何机会你都可以给我一点帮助。
我想为要添加的标记创建一个带有 contentString 的信息窗口。