好的,所以我使用gmap显示来自 xml 文件的许多位置,该文件存储城市、州、html 和有关某些位置的其他信息。这里的问题是很可能有超过 100 个位置。
在 NEW 我的 ajax 调用中:
var myMarkers = new Array;
$(xml).find("location").each(function(){
var locAddress = $(this).find("city").text() + "," + $(this).find("state").text() ;
var cc = $(this).find("cc").text();
var bcc;
if ($(this).find("bcc")){
bcc = $(this).find("bcc").text();
}else{
bcc = " - ";
}
var vendor =$(this).find("vendor").text();
var hours = $(this).find("hours").text();
var HTMLString = "<div class=\"map-balloon\"><h3>" + locAddress + "</h3>Vendor: " + vendor + "<br />CC#: " + cc + "<br />Bulk CC#: " + bcc + "<br />Hours: " + hours + "</div>" ;
myMarkers.push("{ address: \"" + locAddress + "\", html: \"" + HTMLString + "\"}");
});
$("#map").gMap({ markers: [myMarkers.toString()], address: "United States", zoom: 4 }); // shows the correct zoom and region, but markers do not display now.
console.log(myMarkers.toString());//Shows the correct string we want
问题是它每次都加载,firefox 讨厌它并去计算,它在 IE7 中工作。
我的问题是,动态设置多个标记的最佳方法是什么?这是新的工作代码:
var myMarkers = new Array;
$.ajax({
url: "tire-banks.xml",
dataType: ($.browser.msie) ? "text" : "xml",
async: false,
success: function(data){
var xml;
if (typeof data == "string") {
xml = new ActiveXObject("Microsoft.XMLDOM");
// xml.async = false;
xml.loadXML(data);
} else {
xml = data;
}
$(xml).find("location").each(function(){
var locAddress = $(this).find("city").text() + "," + $(this).find("state").text() ;
var cc = $(this).find("cc").text();
var bcc;
if ($(this).find("bcc")){
bcc = $(this).find("bcc").text();
}else{
bcc = " - ";
}
var vendor =$(this).find("vendor").text();
var hours = $(this).find("hours").text();
var HTMLString = "<div><h3>" + locAddress + "</h3>Vendor: " + vendor + "<br />CC#: " + cc + "<br />Bulk CC#: " + bcc + "<br />Hours: " + hours + "</div>" ;
myMarkers.push({ address: locAddress, html: HTMLString});
});