简体   繁体   English

Google Maps,“为null或不是对象”和IE8

[英]Google Maps, “is null or not an object” and IE8

So, i have a Google Maps map in a web site i'm creating and everything runs great in every browser, except for… IE8. 因此,我在正在创建的网站中拥有Google Maps地图,并且除了IE8之外,所有功能都在每个浏览器中都运行良好。 In IE8 the browser simply stops reading the JS file when he encounters the first variable declaration and it gives the error i mentioned in the subject. 在IE8中,当浏览器遇到第一个变量声明时,它只是停止读取JS文件,并且给出了我在主题中提到的错误。 It doesn't load the map neither any function bellow the error. 它不会加载地图,也没有任何函数显示错误。

It's always in the same variable, which means that if i change the code it will always stuck in that part. 它总是在同一个变量中,这意味着如果我更改代码,它将始终停留在该部分中。

So the code is the following: 因此,代码如下:

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

The error is always in the "google.maps" part. 该错误始终在“ google.maps”部分中。 I've read somewhere that it can be related with trailing commas, but 24 hours later i can't find any. 我读过某个地方,它可能与尾随逗号有关,但24小时后我找不到任何地方。

So any ideas? 有什么想法吗?

Try adding map center like this 尝试像这样添加地图中心

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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