我的js脚本代码或html代码错误

时间:2019-11-12 20:26:56

标签: javascript

  

Google ispector:index.html:1未捕获(按承诺)yd {消息:“ initMap不是函数”,名称:“ InvalidValueError”,...

我正在使用布尔玛制作相关内容,并尝试将Google地图放入布尔玛的魔术贴面板中,因此我需要一些帮助来摆脱此错误,因为我无法在网站和论坛上找到解决方案

enter image description here

小幅下跌:

enter image description here

我的initMap函数:

var map;

//initialiser la map

function initMap() {
  var saint_alban_auriolles = {
    lat: 44.4221449,
    long: 4.3051642999999995
  }

  var content = '<h1>Saint Alban Auriolles, France</h1>';
  map = new google.maps.Map(document.getElementById('map'), {
    center: saint_alban_auriolles,
    zoom: 8,
    styles: [{
        "featureType": "administrative",
        "elementType": "labels.text.fill",
        "stylers": [{
          "color": "#444444"
        }]
      },
      {
        "featureType": "landscape",
        "elementType": "all",
        "stylers": [{
          "color": "#f2f2f2"
        }]
      },
      {
        "featureType": "poi",
        "elementType": "all",
        "stylers": [{
          "visibility": "off"
        }]
      },
      {
        "featureType": "road",
        "elementType": "all",
        "stylers": [{
            "saturation": -100
          },
          {
            "lightness": 45
          }
        ]
      },
      {
        "featureType": "road.highway",
        "elementType": "all",
        "stylers": [{
          "visibility": "simplified"
        }]
      },
      {
        "featureType": "road.arterial",
        "elementType": "labels.icon",
        "stylers": [{
          "visibility": "off"
        }]
      },
      {
        "featureType": "transit",
        "elementType": "all",
        "stylers": [{
          "visibility": "off"
        }]
      },
      {
        "featureType": "water",
        "elementType": "all",
        "stylers": [{
            "color": "#46bcec"
          },
          {
            "visibility": "on"
          }
        ]
      }
    ]
  });

  var infos = new google.maps.InfoWindow({
    content: content
  });

  var marker = new google.maps.Marker({
    position: saint_alban_auriolles,
    map: map
  });

  marker.addlistener('click', function() {
    infos.open(map, marker);
  });
}

我的地图也没有消失 this answer

我的CSS Alreay尝试100x100

/*
MAP
*/
#map{
   height: 300px;
   width: 300px;
}

1 个答案:

答案 0 :(得分:0)

未捕获的ReferenceError:未定义initMap     在:1:1