0

我正在使用 Google Maps API 3 显示加拿大的谷歌地图和一堆标记,但在 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>

知道有什么问题吗?

4

2 回答 2

3

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

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

试试看它现在是否有效。

于 2010-11-09T22:49:21.177 回答
0

我的猜测是 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);

 });
于 2010-11-09T22:06:10.943 回答