繁体   English   中英

Google Map不会出现在IE7 / 8中(但可以在IE9中使用)

[英]Google Map does not appear in IE7/8 (but works in IE9)

我正在使用Google Maps API 3显示加拿大的Google地图和一堆标记,但是在IE7 / 8中,它根本没有显示,只是给了我一个灰色矩形。 在Firefox / Chrome / Opera / IE9中可以正常加载。

这是代码:

$(document).ready(function() {
    var browserSupportFlag = new Boolean();
    var map;
    geocoder = new google.maps.Geocoder();
    var myOptions = {
        zoom: 3,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        navigationControl: true,
        mapTypeControl: true,
        scaleControl: true,
        streetViewControl: true,
        navigationControlOptions: {
            style: google.maps.NavigationControlStyle.ZOOM_PAN
        },
        mapTypeControlOptions: {
            style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
        }
    };
    //var bounds = new GLatLngBounds(); 
    map = new google.maps.Map(document.getElementById("dealer-map"), myOptions);

    if (navigator.geolocation) {
        browserSupportFlag = true;
        navigator.geolocation.getCurrentPosition(function(position) {
            currentLocation = new google.maps.LatLng(position.coords.latitude, 
                                                     position.coords.longitude);
            contentString = "Location found using W3C standard";
            map.setCenter(currentLocation);
        }, function() {
        });
    }
    var geoXml = new geoXML3.parser({ map: map });
    geoXml.parse('<?php echo "/dealers.php"; ?>');

});     

并导入使用:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.1&sensor=false&region=CA"></script>

HTML / CSS是:

<div class="main-content">
<div class="wide-content">
<h3>Find a Dealer</h3>
<div style="width: 800px; height: 330px;" id="dealer-map"></div>
</div>
</div>

知道有什么问题吗?

实际上很简单,您在所有情况下都需要执行setCenter,否则将显示一个灰色框。

if( navigator.geolocation ) {
  ...
} else {
  map.setCenter( new google.maps.LatLng(34,-83) );
}

尝试一下,看看它现在是否正在工作。

我的猜测是您的navigator.geolocation.getCurrentPosition函数中的空函数。

navigator.geolocation.getCurrentPosition(function(position) {
        currentLocation = new google.maps.LatLng(position.coords.latitude, 
                                                 position.coords.longitude);
        contentString = "Location found using W3C standard";
        map.setCenter(currentLocation);
        /*infowindow.setContent(contentString); 
        infowindow.setPosition(currentLocation); 
        infowindow.open(map);*/
    }, function() {  // <<< empty function may fubar ie
    });

尝试不使用空函数,如下所示。 只是黑暗中的一击而实际上没有链接可跟随并直接看到问题。

 navigator.geolocation.getCurrentPosition(function(position) {
    currentLocation = new google.maps.LatLng(position.coords.latitude, 
                                                 position.coords.longitude);
        contentString = "Location found using W3C standard";
        map.setCenter(currentLocation);

 });

暂无
暂无

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

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