IE中未加载谷歌地图标记

google map markers not loading in IE

本文关键字:地图 图标 谷歌 加载 IE      更新时间:2023-09-26

我正在使用谷歌地图API。

以下内容在<head>

<script src="http://maps.google.com/maps/api/js?sensor=false"></script>

以下内容在body

<script type="text/javascript">
    var infowindow = new google.maps.InfoWindow({ 
        //size: new google.maps.Size(150,150)
        maxWidth: 500,
    });
    function initialize() {
        var myOptions = {
            zoom: 4,
            center: new google.maps.LatLng(38.90, -99.00),
            mapTypeControl: true,
            mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
            navigationControl: true,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        map = new google.maps.Map(document.getElementById("map"), myOptions);
        var markers = [];

        for (var i = 0; i < businesses.length; i++) {
            var latLng = new google.maps.LatLng(businesses[i].latitude, businesses[i].longitude);
            var marker = createMarker(latLng,businesses[i].name, businesses[i].description);
            markers.push(marker);

        }
    }
    function createMarker(latlng, name, html) {
        var contentString = html;
        var marker = new google.maps.Marker({
            position: latlng,
            map: map,
            zIndex: Math.round(latlng.lat()*-100000)<<5
            });
        google.maps.event.addListener(marker, 'click', function() {
            infowindow.setContent(contentString); 
            infowindow.open(map,marker);
        });
    }

</script>
<script type="text/javascript">
    var businesses = new Array();
</script>

然后我运行一些php,并将其包含在phpforeach语句中

<script type="text/javascript">
    business = {
        name:"<?php echo $i; ?> - Columbia Gorge Blue Grass",
        description:"<?php echo $row['display_name']; ?>",
        address:"$row['address'];",
        latitude:"<?php echo $row['lat']; ?>",
        longitude:"<?php echo $row['lon']; ?>",
        url:"$row['url'];",
        business_type:"Getaway"
    };
    businesses[<?php echo $i; ?>] = business;
</script>

在foreach语句之后,我有映射的div,并调用initialize语句

<div id="map-container"><div id="map"></div></div>
<script>    
    initialize();    
</script>

在Chrome和Firefox中,一切都很好,但在IE中,我会收到"完成,但页面上有错误"的错误。地图在IE中加载良好,但地图上没有显示任何标记。

当我点击IE错误图标时,我会收到以下消息:网页错误详细信息

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; MS-RTC LM 8; InfoPath.3)
Timestamp: Fri, 13 Jan 2012 16:54:36 UTC

Message: Object doesn't support this property or method
Line: 111102061
Char: 3
Code: 0
URI: http://www.domain.com/contractor/listings

我很确定问题发生在调用initialize();时,但我不知道是什么原因导致了问题。

如有任何帮助或见解,我们将不胜感激。

感谢

-Mike

此处尾随逗号:

 maxWidth: 500,

只是一个想法。纬度和经度是浮点数。不确定在这种情况下是否应该用"包装它们。

latitude:"<?php echo $row['lat']; ?>",
longitude:"<?php echo $row['lon']; ?>",

IE可能将它们视为字符串。另一个建议;删除这一行,看看这是否有什么不同:

zIndex: Math.round(latlng.lat()*-100000)<<5