0

我有一个 javascript,它在运行时会从我设置的 MYSQL 表中构建一个 XML 文件。它可以正常工作,并且按计划绘制所有标记。现在,我正在尝试绑定一些下拉过滤器。我已经浏览了许多示例,但无法使其适用于我的示例。

我为下拉列表添加了变量,如下所示:

var MeetingType = document.getElementById("Meeting_Type");
var type = MeetingType.options[MeetingType.selectedIndex].text;
var DayofMeeting = document.getElementById("Day_of_Meeting");
var day = DayofMeeting.options[DayofMeeting.selectedIndex].text;
var TimeofMeeting = document.getElementById("Time_of_Meeting");
var time = TimeofMeeting.options[TimeofMeeting.selectedIndex].text;

现在我试图在创建标记后创建一个数组,所以我可以像这样过滤它们:

for (var i = 0; i < placemarkers.length; i++) {
    if (placemarkers[i].type==type&&placemarkers[i].day==day&&placemarkers[i].time==time){
    placemarkers[i].setMap(MYMAP.map);
    }else{
    clearOverlays();
    mymarkers=[]
        }
    }
}

这是整个代码。谁能帮我把这些值放入一个数组中?我的不工作。

$(document).ready(function() {
$("#map").css({
    height: 500,
    width: 600
});
var myLatLng = new google.maps.LatLng(43.653823, -79.382843);
MYMAP.init('#map', myLatLng, 11);

$("#showmarkers").click(function(e){
    MYMAP.placeMarkers('include/xml.php');
});
});

var MYMAP = {
map: null,
bounds: null
}

MYMAP.init = function(selector, latLng, zoom) {
var myOptions = {
    zoom:zoom,
    center: latLng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
}
this.map = new google.maps.Map($(selector)[0], myOptions);
this.bounds = new google.maps.LatLngBounds();
}

var markerfilter = new Array();
MYMAP.placeMarkers = function(filename) {
$.get(filename, function(xml){
    $(xml).find("marker").each(function(){
        var name = $(this).find('name').text();
        var address = $(this).find('address').text();
        var address2 = $(this).find('address2').text();
        var Meeting_Type = $(this).find('Meeting_Type').text();
        var Time_of_Meeting = $(this).find('Time_of_Meeting').text();
        var Day_of_Meeting = $(this).find('Day_of_Meeting').text();
        var Open_Meeting = $(this).find('Open_Meeting').text();
        var Wheelchair = $(this).find('Wheelchair').text();
        var ASL = $(this).find('ASL').text();
        var Comments = $(this).find('Comments').text();
        markerfilter.push(marker);

        var MeetingType = document.getElementById("Meeting_Type");
        var type = MeetingType.options[MeetingType.selectedIndex].text;
        var DayofMeeting = document.getElementById("Day_of_Meeting");
        var day = DayofMeeting.options[DayofMeeting.selectedIndex].text;
        var TimeofMeeting = document.getElementById("Time_of_Meeting");
        var time = TimeofMeeting.options[TimeofMeeting.selectedIndex].text;

        // create a new LatLng point for the marker
        var lat = $(this).find('lat').text();
        var lng = $(this).find('lng').text();
        var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));

        // extend the bounds to include the new point
        MYMAP.bounds.extend(point);

        var marker = new google.maps.Marker({
            position: point,
            map: MYMAP.map
        });

        var infoWindow = new google.maps.InfoWindow();
        var html='<b><u>'+name+'</b></u><br />'+address2+'<br />'+address+'<br />'+Meeting_Type+',&nbsp'+Time_of_Meeting+',&nbsp'+Day_of_Meeting+'<br />Open Meeting:&nbsp'+Open_Meeting+'<br />Wheelchair Accessible:&nbsp'+Wheelchair+'<br />ASL:&nbsp'+ASL+'<br />Comments:&nbsp'+Comments;
        google.maps.event.addListener(marker, 'click', function() {
            infoWindow.setContent(html);
            infoWindow.open(MYMAP.map, marker);
        });
        MYMAP.map.fitBounds(MYMAP.bounds);
    });
});
}

我已经编辑了我的代码以反映我所做的一些更改,但它仍然无法正常工作。

4

2 回答 2

0

如果有帮助,请尝试使用 jQuery Map Marker 插件,因为它具有很好的灵活性/下面是该插件的链接

http://www.welancers.com/jquery-map-marker-plugin/

于 2012-05-11T04:01:43.880 回答
0

在不知道其余代码的情况下,最直接的方法是

    var marker = new google.maps.Marker({
        position: point,
        map: MYMAP.map
    });
    mymarkers.push(marker);
于 2015-04-13T15:34:59.817 回答