Reputation: 1873
This is inside the google initialize function and works fine. It's the code below which loops through the markers which is getting marker[i] is undefined
$.each(places, function(index, value) {
x++;
var pos = new google.maps.LatLng(value[1], value[2]);
var icon = value[3];
if(value[3] == 'HI') icon = "NF";
if(value[3] == '') icon = "WH";
marker[x] = new google.maps.Marker({
position: pos,
map:map,
title: value[0],
shadow: shadow,
icon: "../img/markers/" + icon + ".png"
});
marker[x].locType = icon;
});
Here's the loop outside the initialize function - Getting marker[i] is undefined
, doing an alert(marker)
gives me [object Object],[object Object],[object Object],[object Object],[object Object]
etc....
$(".team").click(function() {
var type = $(this).attr("id");
$.each(marker, function(i, val) {
if(marker[i].locType == type) marker[i].setVisible(false);
})
});
Upvotes: 0
Views: 193
Reputation: 10315
I think the problem is the
x++;
this probably indicates that your array start at index 1
instead of 0
so you result probably is:
[1] = Object
[2] = Object
etc.
when running the $.each
method it tries
marker[0].locType
Solution is to move the x++
to the end of the $.each(places, function(index, value) {
Upvotes: 1