javascript 未捕获的参考错误:Gmaps.js 错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24505944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught Reference Error: Gmaps.js error?
提问by user3340037
I'm having trouble figuring out how to use the gmaps plugin. I've followed the example given and even looked at the page source and copied it, yet I still have no progress.
我无法弄清楚如何使用 gmaps 插件。我已经按照给出的例子,甚至查看了页面源代码并复制了它,但我仍然没有任何进展。
This is my chunk of html with js files included.
这是我的包含 js 文件的 html 块。
<!DOCTYPE html>
<html>
<head>
<title>testss</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="/javascripts/maps.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=true"></script>
<link href='//fonts.googleapis.com/css?family=Convergence|Bitter|Droid+Sans|Ubuntu+Mono' rel='stylesheet' type='text/css' />
<script>
$(document).ready(function(){
var map = new GMaps({
div: '#map', lat: -12, lng: -77
});
});
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
I'm getting these errors:
我收到这些错误:
Uncaught Google Maps API is required. Please register the following JavaScript library http://maps.google.com/maps/api/js?sensor=true. maps.js:22
需要未捕获的 Google Maps API。请注册以下 JavaScript 库 http://maps.google.com/maps/api/js?sensor=true。地图.js:22
Uncaught ReferenceError: GMaps is not defined
未捕获的 ReferenceError:未定义 GMaps
Not sure why this issue is appearing since I've included the file. Any ideas are much appreciated!
不知道为什么会出现这个问题,因为我已经包含了该文件。任何想法都非常感谢!
If this helps, I'm using node.js and express on localhost.
如果这有帮助,我正在使用 node.js 并在本地主机上表达。
回答by myagi
That's a dependency error. Include http://maps.google.com/maps/api/jsbeforeyour call to /javascript/gmaps.js
这是一个依赖错误。在调用 /javascript/gmaps.js之前包含http://maps.google.com/maps/api/js
回答by sankycse
The error is in the registration url of google maps api. Please use https
instead of http
.
Include this url:
错误出在 google maps api 的注册 url 中。请使用https
代替http
。包括这个网址:
https://maps.google.com/maps/api/js?sensor=true
回答by Kevin Sandow
I'm not sure, who was using the wrong documentation your or I, but this seems to be working quite fine:
我不确定是谁使用了你或我的错误文档,但这似乎工作得很好:
<!DOCTYPE html>
<html>
<head>
<title>testss</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="/javascripts/maps.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=true"></script>
<link href='//fonts.googleapis.com/css?family=Convergence|Bitter|Droid+Sans|Ubuntu+Mono' rel='stylesheet' type='text/css' />
<script>
$(document).ready(function(){
var map = new google.maps.Map(
document.getElementById('map'),
{
zoom: 15,
center: new google.maps.LatLng(-12, -77)
}
);
});
</script>
</head>
<body>
<div id="map" style="height: 20em;"></div>
</body>
</html>
edit:I just realized you were trying to use gmaps.js- but in that case you're missing the gmaps.js file unless that is what your maps.js was for.
编辑:我刚刚意识到您正在尝试使用gmaps.js- 但在这种情况下,您将缺少 gmaps.js 文件,除非这是您的 maps.js 的用途。
You can download the current version at: https://raw.githubusercontent.com/HPNeo/gmaps/master/gmaps.js
您可以在以下位置下载当前版本:https: //raw.githubusercontent.com/HPNeo/gmaps/master/gmaps.js