javascript - Unexpected call with google maps in IE8 -
i'm using google map api design "earthquake map". far, good.
the map displays nicely in firefox , chrome raises error in ie8:
webpage error details
user agent: mozilla/4.0 (compatible; msie 7.0; windows nt 5.1; trident/4.0; .net clr 1.1.4322; .net clr 2.0.50727; infopath.3) timestamp: fri, 3 may 2013 08:13:44 utc
message: unexpected call method or property access. line: 9 char: 238 code: 0 uri: http://maps.gstatic.com/intl/pt_all/mapfiles/api-3/12/10/main.js
<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>google maps multiple markers</title> <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> </head> <body> <div id="map" style="width: 400px; height: 650px;"></div> <script type="text/javascript"> var parsed = [[]]; var txtfile; if (window.xmlhttprequest) { // mozilla, safari, ... txtfile = new xmlhttprequest(); } else if (window.activexobject) { // ie 8 , older txtfile = new activexobject("microsoft.xmlhttp"); } txtfile.open("get", "http://foo/f4/stats/nservscodigopostal.csv", true); txtfile.onreadystatechange = function(){ if (txtfile.readystate === 4){ // makes sure document ready parse. if (txtfile.status === 200){ // makes sure it's found file. alltext = txtfile.responsetext; parsed = csvtoarray(alltext, ";") } } function csvtoarray( strdata, strdelimiter ){ strdelimiter = (strdelimiter || ","); var objpattern = new regexp( ( // delimiters. "(\\" + strdelimiter + "|\\r?\\n|\\r|^)" + // quoted fields. "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" + // standard fields. "([^\"\\" + strdelimiter + "\\r\\n]*))" ), "gi" ); var arrdata = [[]]; var arrmatches = null; while (arrmatches = objpattern.exec( strdata )){ var strmatcheddelimiter = arrmatches[ 1 ]; if ( strmatcheddelimiter.length && (strmatcheddelimiter != strdelimiter) ){ arrdata.push( [] ); } if (arrmatches[ 2 ]){ var strmatchedvalue = arrmatches[ 2 ].replace( new regexp( "\"\"", "g" ), "\"" ); } else { var strmatchedvalue = arrmatches[ 3 ]; } arrdata[ arrdata.length - 1 ].push( strmatchedvalue ); } return( arrdata ); } var locations = [ ['viana castelo', 41.6872711837914, -8.82476806640625, ], ['braga', 41.54944320851238, -8.414154052734375, ], ['porto', 41.15875373498798, -8.610706329345703, ], ['aveiro', 40.63896734381723,-8.648300170898438, ], ['vila real', 41.30050773444147, -7.752227783203125, ], ['bragança', 41.80535774441799, -6.760368347167969, ], ['viseu', 40.64730356252251, -7.8936767578125, ], ['guarda', 40.53258931069557, -7.25921630859375, ], ['coimbra', 40.20195268954057, -8.433380126953125, ], ['leiria', 39.7462660621837, -8.81103515625, ], ['santarém', 39.774769485295465, -8.5693359375, ], ['castelo branco', 39.82013946676259, -7.505035400390625, ], ['portalegre', 39.28860847419942, -7.42950439453125, ], ['lisboa', 38.72891158257716, -9.139251708984375, ], ['Èvora', 38.56749535882734, -7.9046630859375, ], ['setúbal', 38.5299046000139, -8.876953125, ], ['beja', 38.01509916686995, -7.862606048583984, ], ['faro', 37.017905231730914, -7.922515869140625, ] ]; (var = 0; i<parsed.length; i++){ var = new string(parsed[i][0]); parsed[i][0] = a.replace(/[^a-z0-9]/gi,''); for(var j = 0; j<locations.length; j++){ var b = new string(locations[j][0]); locations[j][0] = b.replace(/[^a-z0-9]/gi,''); if(parsed[i][0]==locations[j][0]){ locations[j][3] = ((0.07*parsed[i][2])+4.875); } } } var map = new google.maps.map(document.getelementbyid('map'), { zoom: 7, center: new google.maps.latlng(39.50, -8.37), disabledefaultui: true, maptypeid: google.maps.maptypeid.roadmap }); var infowindow = new google.maps.infowindow(); for( var = 0; < locations.length; i++ ) { addmarker( locations[i] ); } function addmarker( location ) { var lat = location[1], lng = location[2], magnitude = location[3], content = location[0]; var options = { position: new google.maps.latlng( lat, lng ), map: map }; if( magnitude < 5 ) { options.animation = google.maps.animation.bounce; } else { options.icon = getcircle( magnitude ); } var marker = new google.maps.marker( options ); google.maps.event.addlistener( marker, 'click', function() { infowindow.setcontent( content ); infowindow.open( map, marker ); }); } function getcircle(magnitude) { return { path: google.maps.symbolpath.circle, fillcolor: 'red', fillopacity: .5, scale: math.pow(2, magnitude) / math.pi, strokecolor: 'black', strokeweight: .5 }; } }; txtfile.send(null); </script> </body> </html> my source code above. can me?
thanks in advance.
update1: new source code same problem.
update2: run firebug, no problem found.
try running code through jslint
your main problem trailing commas after last element in each array, e.g.:
['beja', 38.01509916686995, -7.862606048583984, ], do instead:
['beja', 38.01509916686995, -7.862606048583984 ], this crash ie. there other more minor problems code jslint reveal.
Comments
Post a Comment