在IE8谷歌地图意外呼叫(Unexpected call with google maps in I

2019-10-18 03:04发布

我使用谷歌地图API来设计一个“地震地图”。 到现在为止还挺好。

地图显示在很好Firefox和Chrome,但在IE8提出了一个错误:

网页错误详细信息

用户代理:Mozilla的/ 4.0(兼容; MSIE 7.0; Windows NT的5.1;三叉戟/ 4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.3)日期和时间:星期五,2013年5月3日8点十三分44秒世界标准时间

信息:意外调用方法或属性的访问。 行:9字符:238代码: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 and 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 the document is ready to parse.
    if (txtFile.status === 200){  // Makes sure it's found the 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 do 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, ]
    ];

    for (var i = 0; i<Parsed.length; i++){
    var a = 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 i = 0;  i < 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>

我的源代码是上方。 你能帮助我吗?

提前致谢。

UPDATE1: 新的源代码 ,但同样的问题。

UPDATE2:运行萤火虫,没有发现问题。

Answer 1:

试图通过运行代码的JSLint

你的主要问题是每个阵列,例如,在最后一个元素之后的尾随逗号:

['Beja', 38.01509916686995, -7.862606048583984, ],

做到这一点,而不是:

['Beja', 38.01509916686995, -7.862606048583984 ],

这将始终崩溃IE。 有与JSLint的,就会发现代码中的一些其他更小的问题。



Answer 2:

不是答案只是一些信息。 这个问题可能不是你的代码中有IE8和谷歌应用程序(包括Google地图API)之间的问题之内。 谷歌结束了对IE8今年11月15日支持http://support.google.com/a/bin/answer.py?hl=en&answer=33864

从谷歌这个简单的例子网页会崩溃IE8,它会加载罚款,按F5和IE浏览器会崩溃。 https://developers.google.com/maps/documentation/javascript/examples/full/map-simple

谷歌的确推出的更新地图4月29日增加了一些功能,造成夜间失败在我们的实验室,由于这个问题。 我还没有找到其修订或变通方法。

你需要一个; 在此结束:解析的= CSVToArray(allText, “;”)?



Answer 3:

其他答案并没有为我工作。 思路一打之后,我结束了以下工作溶液(!):

加载内容之前,消灭该地图被附加到对象。

例如,如果你的地图是使用设置:

map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

做Ajax请求之前使用此代码:

$('#map-canvas').remove();



文章来源: Unexpected call with google maps in IE8