开发者

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

I am using Google Maps API 3 to show a google map of Canada and a bunch of markers, but in IE7/8, it doesn't show up at all and just gives me a grey rectangle. It loads fine in Firefox/Chrome/Opera/IE9.

Here is the code:

$(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"; ?>');

});     

And importing using:

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

The HTML/CSS is:

<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>

Any idea what could be wrong?


Simple actually, you need to do a setCenter in all cases or else a gray box is displayed.

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

Try that and see if it's working now.


My guess would be the empty function in your navigator.geolocation.getCurrentPosition function.

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
    });

Try it without the empty function, like below. Just a stab in the dark without actually having a link to follow and see the issue first hand.

 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);

 });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜