0

我有一个页面,可以在数据库中搜索输入邮政编码中的商店,将它们映射为谷歌地图上的 POI,并在单击“显示地图”时显示地图。我的问题是地图似乎只为每次点击生成。我提供了生成表和地图的代码(在同一个 ajax 调用中)。

更具体地说,我所指的点击是调用 ajax 代码的搜索功能的触发器,而不是“显示地图”点击。换句话说,当我第一次搜索邮政编码时,我可以查看地图。第二次搜索没有产生地图,第三次产生地图......等等......

非常感激任何的帮助

代码如下:

function retrieve_stores_in_prox(){
    $('.trigger2').click(function() {   
        $("#map_store").each(function(){
            if ($(this).css("display") == "none")
            {
                $(this).css("display", "block");
            }
            else
            {
                $(this).css("display", "none");
             }
        })
    });
$(document).ready(function() {
    $('#storeList').empty().trigger("update");
    //initialize the store map

    var redicon = new GIcon();
    redicon.image = "images/redCircle.png";
    redicon.iconSize = new GSize(11, 11);
    redicon.iconAnchor = new GPoint(6, 6);
    redicon.infoWindowAnchor = new GPoint(6,6);

    $.ajax({
    type: 'post',
    url: 'trip_planner_store.php',
    dataType: "xml",
    cache: false,
    data: {zip:$("#zip").val()},
    success: function(data) {
        var storemap = new GMap2(document.getElementById("map_store"), { size: new GSize(500,320) });
        storemap.addControl(new GLargeMapControl());
        storemap.addControl(new GMapTypeControl());

        var lat1 = $(data).find('LAT1').text();
        var lon1 = $(data).find('LON1').text();
        storemap.setCenter(new GLatLng(lat1,lon1),8);
        google.maps.event.trigger(storemap, 'resize');

        $(data).find('STORE').each(function(index){
        var lat = parseFloat($(this).find('LATITUDE').text());
        var long = parseFloat($(this).find('LONGITUDE').text());

        var marker = new GMarker(new GLatLng(lat,long), { 
            draggable: false, 
            title: ($(this).find('COMPANY_NAME').text()), 
            icon: redicon,
            disableAutoPan: true,
            supressMapPan: true
        });

        var html = {some stuff for the info window}
                    GEvent.addListener(marker, 'mouseover', function() {
            // When clicked, open an Info Window
                        marker.openInfoWindowHtml(html);

                    });
        storemap.addOverlay(marker);
        //update the store table with the information


           var storeList = {html markup for table};


           //append the current row to the installer table
        $('#storeList').append(storeList);

    });
    $('#storeList').trigger("update");

    }
});
});

}

4

1 回答 1

0

我已经解决了这个难题。错误实际上是我的点击触发事件位于函数调用中。我将它移到我的脚本标签的顶部,它现在按预期运行。我不知道为什么在被调用函数中触发点击事件只适用于其他所有调用。任何猜测将不胜感激。

于 2012-09-17T19:39:52.490 回答