views:

49

answers:

1

The code works fine in Firefox, but not in IE8. I'm getting an error: 'address' is null or not an object.

Have been googling for days and couldn't get a clear answer on how to fix/debug this. Hope stackoverflow.com can help.

var latlng = [
      {
address: new GLatLng(-6.1364941,106.8000411),
marker0: myIcon0
},
      {
address: new GLatLng(-6.1364941,106.8000411),
marker0: myIcon0
},
      {
address: new GLatLng(1.3520831,103.8198361),
marker0: myIcon0
},
      {
address: new GLatLng(14.06666671,121.33333331),
marker0: myIcon
},
    ];
  var markers = []; 
  for ( var i = 0; i < latlng.length; i++ )
    {
      var marker = new GMarker( latlng[ i ].address, latlng[ i ].marker0 );
      map.addOverlay( marker );
      markers[i] = marker;
    }
    $(markers).each(function(i,marker){ 
      GEvent.addListener(marker,"click", function(){ 
        // map.panTo(marker.getLatLng());
        map.setCenter(marker.getLatLng(), 10);
        marker.openInfoWindowHtml($('.view-display-id-attachment_1 .views-row-'+(i+1)).html(), {maxWidth:200});
      });
      $("<li />") 
        .html($('.view-display-id-attachment_1 .views-row-'+(i+1)).html()) 
        .click(function(){ 
          map.setCenter(marker.getLatLng(), 10);
          marker.openInfoWindowHtml($('.view-display-id-attachment_1 .views-row-'+(i+1)).html(), {maxWidth:200}); // custom balloon text
          // alert($('.view-display-id-attachment_1 .views-row-'+(i+1)).html()); // VIEWS ROW COUNT DEBUG
        }) 
        .appendTo("#wtb-list");
    });
+3  A: 

The issue is here:

marker0: myIcon
},  //<-- here!
    ];

that trailing comma at the end of your array declaration will give IE8 issues, remove it :) Other browsers..."overlook?" this in most cases, IE will always error on them.

Nick Craver
3mins, you are fast!
logii
Nick, thanks, really. =)
logii
@logii - :) Did that take care of it?
Nick Craver
+1 beat me to it. I have been burned by the trailing comma a few times myself :)
David Hedlund
@David - Aye, the fact that C# allows it (to make code gen easier and such) makes it even easier to overlook, at least to me switching back and forth.
Nick Craver
@Nick it did work. Now everything sits nicely on IE. Words cannot describe how I feel now ;)
logii
@Nick you are that fast that I have to wait 6mins to be able to check off your answer as the right one =\
logii
To complete the whole processing, I have fixed it with var strLen = latlng.length; latlng = latlng.slice(0,strLen-1);This replaces the trailing comma by removing the last character of the 'latlng'
logii