jquery gMap有很多动态位置

好的,所以我使用gmap显示来自xml文件的许多locatons,该文件存储城市,州,html和某些位置的其他信息。这里的问题很可能是超过100个位置。

在新的我的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 = "

" + locAddress + "

Vendor: " + vendor + "
CC#: " + cc + "
Bulk CC#: " + bcc + "
Hours: " + hours + "
" ; 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 = "

" + locAddress + "

Vendor: " + vendor + "
CC#: " + cc + "
Bulk CC#: " + bcc + "
Hours: " + hours + "
" ; myMarkers.push({ address: locAddress, html: HTMLString}); });

我认为你应该尝试像你一样创建JSON对象,并在完成后同时创建每个标记。 (我不确定你是否应该使用它,但你明白了)。

 // With something like : var myMarkers = ""; // 'Each' loop { myMarkers += "{ address: "+locAddress+", html: "+HTMLString+"},"; // End 'Each' loop } // Don't forget to remove the trailing ',' $("#map").gMap({ markers: [myMarkers] });