jquery gMap有很多动态位置

时间:2011-06-14 13:53:05

标签: jquery jquery-gmap

好的,我正在使用gmap来显示存储城市,州,html和某些位置的其他信息的xml文件中的许多位置。这里的问题很可能超过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 =  "<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});   
                    });

1 个答案:

答案 0 :(得分:0)

我认为你应该尝试像你一样创建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] });