简体   繁体   English

IE8中的Google地图意外呼叫

[英]Unexpected call with google maps in IE8

I'm using google map API to design a "earthquake map". 我正在使用Google Map API设计“地震地图”。 So far, so good. 到现在为止还挺好。

The map displays nicely in Firefox and Chrome but raises a error in IE8: 该地图在Firefox和Chrome中可以很好地显示,但在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 用户代理:Mozilla / 4.0(兼容; MSIE 7.0; Windows NT 5.1; Trident / 4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.3)时间戳:2013年5月3日星期五08:13:44世界标准时间

Message: Unexpected call to 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 行: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>

My source code is above. 我的源代码在上面。 Can you help me? 你能帮助我吗?

Thanks in advance. 提前致谢。

Update1: New Source code but same problem. Update1: 新的源代码,但存在相同的问题。

Update2: Run Firebug, no problem was found. Update2:运行Firebug,没有发现问题。

Try running the code through JSLint 尝试通过JSLint运行代码

Your main problem is the trailing commas after the last element in each array, eg: 您的主要问题是每个数组中最后一个元素之后的结尾逗号,例如:

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

Do this instead: 改为这样做:

['Beja', 38.01509916686995, -7.862606048583984 ],

This will always crash IE. 这将始终使IE崩溃。 There are some other more minor problems with the code that JSLint will reveal. JSLint将揭示的代码还有其他一些小问题。

Not an answer just some info. 没有答案,只是一些信息。 The problem may not be within your code there is an issue between IE8 and Google apps ( including Maps api). 问题可能不在您的代码之内,IE8和Google应用程序(包括Maps api)之间存在问题。 Google ended support for IE8 this past November 15th http://support.google.com/a/bin/answer.py?hl=en&answer=33864 Google于11月15日结束了对IE8的支持http://support.google.com/a/bin/answer.py?hl=zh_CN&answer=33864

This simple example page from Google will crash IE8, it will load fine, press F5 and IE will crash. Google的这个简单示例页面将使IE8崩溃,它将正常加载,按F5键将导致IE崩溃。 https://developers.google.com/maps/documentation/javascript/examples/full/map-simple https://developers.google.com/maps/documentation/javascript/examples/full/map-simple

Google did push out an update to Maps on April 29th enhancing some features, which caused nightly failures in our lab, due to this issue. Google确实在4月29日推出了Google Maps更新,以增强某些功能,由于此问题,这导致了我们实验室的每夜故障。 I have not found a fix or workaround for it. 我没有找到修复或解决方法。

Do you need a ; 你需要一个; at the end of this: Parsed = CSVToArray(allText, ";") ? 在此结尾:Parsed = CSVToArray(allText,“;”)?

The other answers did not work for me. 其他答案对我不起作用。 After a dozen of ideas, I ended up with the following working(!) solution: 经过一番构想,我得出了以下可行的解决方案:

Before loading the content, destroy the object that the map is attached to. 加载内容之前,请销毁地图附加到的对象。

eg if your map is set using: 例如,如果您的地图是使用以下方法设置的:

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

use this code before doing the ajax request: 在执行ajax请求之前使用以下代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM