Google地图 - 未捕获InvalidValueError:初始化不是函数 [英] Google Maps - Uncaught InvalidValueError: initialise is not a function
问题描述
未捕获的InvalidValueError:初始化不是一个函数传感器=假&回调=初始化:94
这显示为来自 https://maps.googleapis .com / maps / api / js?sensor = false& callback = initialise
Google地图窗口和地图显示效果绝佳,功能齐全。奇怪的是,我在Google上找不到任何匹配,他们似乎都是关于setLong和setLat。
和JS文件,错误消息在 initialise
和 google
之间变化。但在这两种情况下,地图仍然继续加载罚款。 为什么错误发生,以及如何正确解决它?这是我的google-map.js文件:
function initialise(){
var myLatlng = new google.maps。 LatLng(51.126500,0.257595); //添加坐标
var mapOptions = {
zoom:15,//地图加载时的初始缩放级别(0-20)
disableDefaultUI:true,//禁用地图UI
center:myLatlng,//将地图居中到我们的坐标变量
mapTypeId:google.maps.MapTypeId.ROADMAP,//设置地图的类型
scrollwheel:false,//禁用鼠标滚动缩放(对响应网站至关重要!)
//以下所有设置默认设置为true,所以只需将其设置为true即可:
panControl:false,//设置为false以禁用
mapTypeControl:false,//禁用地图/卫星切换
scaleControl:false,//设置为false以隐藏比例
streetViewControl:false,//设置为禁用以隐藏街景
overviewMapControl:false,//设置为false以移除概览控件
rotateControl:false //设置为false以禁用旋转控件
}
var map = new google.maps.Map(document .getElementById ('map'),mapOptions); //在空div内渲染我们的地图
var image = new google.maps.MarkerImage('/ wp-content / themes / bellavou / img / marker2.png',null,null,null,new google.maps .Size(70,70)); //为我们的标记图像创建一个变量。
var marker = new google.maps.Marker({//设置标记
位置:new google.maps.LatLng(51.125887,0.258075),//将标记位置坐标
图标: image,//使用我们的图像作为标记
map:map,//将市场分配给我们的地图变量
title:'The Pantiles的Bella Vou'//标记ALT Text
} );
}
google.maps.event.addDomListener(window,'load',initialise); //在页面加载后执行我们的'初始化'函数。
首先,在API调用中定义一个回调:
https://maps.googleapis.com/maps/api/js?sensor=false&callback=initialise
然后添加一个侦听器
google.maps.event.addDomListener(窗口,'加载',初始化);
基本上都是这样。
< hr>
您应该从API调用或中移除 callback = initialise
strong>上面提到的 addDomListener
从你的JS文件开始,它应该可以工作。
When I load the page that my Google Maps is displayed, I always see the following error in the console:
Uncaught InvalidValueError: initialise is not a function js?sensor=false&callback=initialise:94
When hovering over the filename, this is showing as originating from https://maps.googleapis.com/maps/api/js?sensor=false&callback=initialise
The Google Maps window and map displays absolutely fine though and has full functionality. Strangely, I couldn't find any hits on Google regarding this, they all seem to be about setLong and setLat.
If I change the order of loading between the API call, and the JS file, the error message changes between initialise
and google
. But in both cases, the map still continues to load fine.
Why is the error occuring, and how do I resolve it properly? Here's my google-map.js file:
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.
First, you define a callback on the API call:
https://maps.googleapis.com/maps/api/js?sensor=false&callback=initialise
then you add a listener
google.maps.event.addDomListener(window, 'load', initialise);
that basically does the same.
You should remove the callback=initialise
from the API call or the above mentioned addDomListener
line from your JS file and it should work.
这篇关于Google地图 - 未捕获InvalidValueError:初始化不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!