I have a javascript that when runs, will build an XML file from my MYSQL table that I have setup. It works and it plots all the markers just as planned. Now, I am trying to tie in some dropdown filters. I have scoured through many examples, but cannot make it work for mine.
I added the variables for the drop downs like this:
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;
Now I am trying to create an array of my markers after they are created, so I can filter them like so:
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=[]
}
}
}
Here is the whole code. Can anyone help me get these values into an array? Mine is not working.
$(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+', '+Time_of_Meeting+', '+Day_of_Meeting+'<br />Open Meeting: '+Open_Meeting+'<br />Wheelchair Accessible: '+Wheelchair+'<br />ASL: '+ASL+'<br />Comments: '+Comments;
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(MYMAP.map, marker);
});
MYMAP.map.fitBounds(MYMAP.bounds);
});
});
}
I have edited my code to reflect some changes I made but it is still not working.
Try the jQuery Map Marker plugin if it helps, as it has good flexibility/ Below is the link for that
Without knowing the rest of your code, the most direct way would be to
var marker = new google.maps.Marker({
position: point,
map: MYMAP.map
});
mymarkers.push(marker);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.