0
好的,所以我使用gmap來顯示許多來自xml文件的位置,這些文件存儲有關某些位置的城市,州,html和其他信息。此處的問題最有可能超過100個地點。有很多動態位置的jquery gMap
內新我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
問題的,這是它在每次加載,火狐討厭它,去的身影,它工作在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});
});
好的,我喜歡你的想法。我更新了我的代碼以反映。我選擇走數組的路線,考慮尾隨逗號,Array.toString()產生相同的效果(我認爲)。在console.log()區域生成我們想要的那個區域中正確的字符串。所以,仍然沒有工作。 – 2011-06-14 15:46:45
通過不工作,你的意思是它仍然緩慢與Firefox?或者你有任何錯誤拋出? – 2011-06-15 07:27:02
對不起,我在上面的代碼中提出了註釋。顯示正確的縮放和區域,但標記現在不顯示。 – 2011-06-15 13:12:47