【问题标题】:Google Maps - Uncaught InvalidValueError: initialise is not a function谷歌地图 - 未捕获的 InvalidValueError:初始化不是函数
【发布时间】:2016-11-17 01:44:38
【问题描述】:

当我加载显示我的 Google 地图的页面时,我总是在控制台中看到以下错误:

未捕获的 InvalidValueError:初始化不是函数js?sensor=false&callback=initialise:94

将鼠标悬停在文件名上时,显示为源自https://maps.googleapis.com/maps/api/js?sensor=false&callback=initialise

虽然 Google 地图窗口和地图显示得非常好,但功能齐全。奇怪的是,我在 Google 上找不到任何关于此的点击,它们似乎都与 setLong 和 setLat 有关。

如果我更改 API 调用和 JS 文件之间的加载顺序,错误消息会在 initialisegoogle 之间更改。但在这两种情况下,地图仍然可以正常加载。

为什么会出现错误,我该如何正确解决?这是我的 google-map.js 文件:

function initialise() {
    var myLatlng = new google.maps.LatLng(51.126500, 0.257595); // Add the coordinates
    var mapOptions = {
        zoom: 15, // The initial zoom level when your map loads (0-20)
        disableDefaultUI: true, // Disable the map UI
        center: myLatlng, // Centre the Map to our coordinates variable
        mapTypeId: google.maps.MapTypeId.ROADMAP, // Set the type of Map
        scrollwheel: false, // Disable Mouse Scroll zooming (Essential for responsive sites!)
    // All of the below are set to true by default, so simply remove if set to true:
    panControl:false, // Set to false to disable
    mapTypeControl:false, // Disable Map/Satellite switch
    scaleControl:false, // Set to false to hide scale
    streetViewControl:false, // Set to disable to hide street view
    overviewMapControl:false, // Set to false to remove overview control
    rotateControl:false // Set to false to disable rotate control
    }
    var map = new google.maps.Map(document.getElementById('map'), mapOptions); // Render our map within the empty div
    var image = new google.maps.MarkerImage('/wp-content/themes/bellavou/img/marker2.png', null, null, null, new google.maps.Size(70,70)); // Create a variable for our marker image.             
    var marker = new google.maps.Marker({ // Set the marker
        position: new google.maps.LatLng(51.125887, 0.258075), // Position marker to coordinates
        icon:image, //use our image as the marker
        map: map, // assign the market to our map variable
        title: 'Bella Vou at The Pantiles' // Marker ALT Text
    });
}
google.maps.event.addDomListener(window, 'load', initialise); // Execute our 'initialise' function once the page has loaded.

【问题讨论】:

  • 不发布您的代码,我们怎么能提供帮助?
  • 不确定你是否需要它,但好的,我会发布它......
  • 首先,在 API 调用 https://maps.googleapis.com/maps/api/js?sensor=false&callback=initialise 上定义一个回调,然后添加一个基本相同的侦听器 google.maps.event.addDomListener(window, 'load', initialise);。删除该侦听器行或从 API 调用中删除 callback=initialise,让我们知道它是否工作得更好。
  • 是的,我从 API 调用中删除了 callback=initialise,并且错误已删除。谢谢你,准备好后添加为答案!
  • 很酷,它可以工作。不客气!

标签: javascript jquery google-maps google-maps-api-3


【解决方案1】:

首先,您在 API 调用上定义一个回调:

https://maps.googleapis.com/maps/api/js?sensor=false&callback=initialise

然后你添加一个监听器

google.maps.event.addDomListener(window, 'load', initialise);

基本上是一样的。


您应该删除 API调用中的callback=initialise上面提到的addDomListener JS文件中的行,它应该可以工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-16
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多