[英]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. 我正在使用Google Maps API 3显示加拿大的Google地图和一堆标记,但是在IE7 / 8中,它根本没有显示,只是给了我一个灰色矩形。 It loads fine in Firefox/Chrome/Opera/IE9.
在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®ion=CA"></script>
The HTML/CSS is: 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>
Any idea what could be wrong? 知道有什么问题吗?
Simple actually, you need to do a setCenter in all cases or else a gray box is displayed. 实际上很简单,您在所有情况下都需要执行setCenter,否则将显示一个灰色框。
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函数中的空函数。
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);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.