[英]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®ion=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.