谷歌地图,“无效或不是对象”和IE8

时间:2013-09-27 23:17:44

标签: javascript google-maps google-maps-api-3 internet-explorer-8

所以,我在我正在创建的网站上有一张谷歌地图地图,除了... IE8外,所有浏览器都运行良好。在IE8中,浏览器在遇到第一个变量声明时只是停止读取JS文件,它给出了我在主题中提到的错误。它不会加载地图,也不会加载错误。

它始终在同一个变量中,这意味着如果我更改代码,它将始终停留在该部分。

所以代码如下:

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小时后我找不到任何逗号。

所有想法?

1 个答案:

答案 0 :(得分:0)

尝试像这样添加地图中心

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