谷歌地图v3标记没有显示即8和9

时间:2015-04-08 13:19:43

标签: javascript internet-explorer google-maps-api-3

我正在尝试将Google地图标记显示在IE 8和9中。以下我认为问题所在:

var addresses = mapAddresses;
//alert(addresses);
if (addresses != null)
{
    var marker, x;
    var infowindow = new google.maps.InfoWindow();

    for (x = 0; x < addresses.length; x++) {
        //alert(addresses.length);
        //alert('http://maps.googleapis.com/maps/api/geocode/json?address=' + addresses[x]);
        $.getJSON('http://maps.googleapis.com/maps/api/geocode/json?address=' + addresses[x] + '&sensor=false', null, function (data) {

            var p = data.results[0].geometry.location
            //alert(data.results[0].formatted_address);  // This will alert the individual addresses.

            var latlng = new google.maps.LatLng(p.lat, p.lng);
            var marker = new google.maps.Marker({
                position: latlng,
                map: map,
                title: data.results[0].formatted_address
            });

            // Add the markers to the gmarkers array.
            gmarkers.push(marker);  //<-------- No markers appear to be getting in here.
        });            
    }

    geoCodeAddress(map);
}

我可以在IE 10 +,FF和Chrome中看到标记。我没有看到调试器中的任何js错误表明存在错误。我验证了$ .getJSON()调用返回结果。任何帮助表示赞赏。谢谢!

1 个答案:

答案 0 :(得分:1)

在Windows XP上尝试之后..事实证明这不是谷歌地图,我的意思是我可以静态添加标记。相反,我意识到它实际上是IE 8 + 9上CORS的问题。

正如您在caniuse.com中所看到的,IE 8和IE 9仅对CORS有部分支持。在wiki中也有人说:

  

Internet Explorer直到版本10才实现CORS。之前的两个版本(8和9)通过XDomainRequest API提供了类似的功能。现在所有现代浏览器(桌面和移动设备)都支持它

有讨论说使用jQuery.support.cors = true;会使它有效,但遗憾的是我的Windows XP + IE 8没有运气。

一些更有帮助的读物:
'jQuery.getJSON' not working in Internet Explorer 8
jQuery issue in Internet Explorer 8

相关问题