简体   繁体   中英

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

 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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