所以,我正在创建的网站中有一个 Google map ,并且在每个浏览器中一切都运行良好,除了……IE8。在 IE8 中,当浏览器遇到第一个变量声明时,浏览器会停止读取 JS 文件,并给出我在主题中提到的错误。它不会加载 map ,也不会加载错误下方的任何函数。
它始终位于同一个变量中,这意味着如果我更改代码,它将始终卡在该部分中。
所以代码如下:
var monteiros_xs = new google.maps.LatLng(40.562884,-7.113948);
var MY_MAPTYPE_ID = 'custom_style';
function calculateCenter() {
center = map.getCenter();
}
function initialize() {
var featureOpts = [
{
stylers: [
{ hue: '#b0d57d' },
{ visibility: 'on' },
{ gamma: 0 },
{ weight: 1 }
]
},
{
elementType: 'labels',
stylers: [
{ visibility: 'on' }
]
},
{
featureType: 'water',
stylers: [
{ color: '#f1f2f2' }
]
}
];
var mapOptions;
mapOptions = {
scrollwheel: false,
zoom: 10,
center: monteiros_xs,
disableDefaultUI: true,
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, MY_MAPTYPE_ID]
},
mapTypeId: MY_MAPTYPE_ID
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var styledMapOptions = {
name: 'Granigri'
};
var rectangulo = new google.maps.Rectangle({
strokeColor: '#3c3c3c',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#1a1a1a',
fillOpacity: 0.35,
map: map,
bounds: new google.maps.LatLngBounds(new google.maps.LatLng(40.560884,-7.119948), new google.maps.LatLng(40.566884,-7.112948))
});
if(rectangulo !== "") {}
var customMapType = new google.maps.StyledMapType(featureOpts, styledMapOptions);
map.mapTypes.set(MY_MAPTYPE_ID, customMapType);
google.maps.event.addDomListener(map, 'idle', function() {
calculateCenter();
});
google.maps.event.addDomListener(window, 'resize', function() {
map.setCenter(center);
});
}
$(document).ready(function(){
initialize();
});
错误始终出现在“google.maps”部分。我在某处读到它可能与尾随逗号有关,但 24 小时后我找不到任何内容。
有什么想法吗?
最佳答案
尝试像这样添加 map 中心
var mapOptions;
mapOptions = {
scrollwheel: false,
zoom: 10,
center: new google.maps.LatLng(40.562884,-7.113948),
disableDefaultUI: true,
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, MY_MAPTYPE_ID]
},
mapTypeId: MY_MAPTYPE_ID
};
关于javascript - 谷歌地图、 "is null or not an object"和 IE8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19061494/