Javascript Google Maps API:TypeError:a 未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32691295/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 14:05:42  来源:igfitidea点击:

Google Maps API: TypeError: a is undefined

javascripthtmlgoogle-maps-api-3

提问by PHP Noob

I have searched this problem all over the web and none of them seem to give me any resolution. I have a simple script to just display the map of South Africa.

我已经在整个网络上搜索了这个问题,但似乎没有一个给我任何解决方案。我有一个简单的脚本来显示南非的地图。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge, chrome=1" />
<title>Map Test</title>
<script language="javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true"></script>
<style>
#map-canvas {
    height: 300px;
    width: 980px;
    margin: 0;
    padding: 0;
    margin-top: 10px;
}
</style>
</head>
<body>
<div id="map-canvas" class="map_canvas"></div>
<script type="text/javascript">
    function initialize()
    {
        var mapOptions = {
            center: new google.maps.LatLng(-29.09958,26.18434),
            zoom: 5,
            mapTypeControlOptions: {
                position: google.maps.ControlPosition.TOP_LEFT
            }
        };
        map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
    }
    google.maps.event.addDomListener(window, 'load', initialize);
</script>
</body>
</html>

But I keep on getting the same error over and over. I have even tried on a different server.

但我一遍又一遍地得到同样的错误。我什至在不同的服务器上尝试过。

enter image description here

在此处输入图片说明

Please help

请帮忙

回答by Dr.Molle

I've also seen this error often in the last days, there seems to be an issue with the experimental API-version.

最近几天我也经常看到这个错误,实验 API 版本似乎有问题。

Load the release-version instead(basically you should always load the release-version in production)

改为加载发布版本(基本上你应该总是在生产中加载发布版本)

<script language="javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true&v=3"></script>

回答by Daniela

Google Maps started to through errors when loading the script and on touch events. I'm using it for a cordova application on Android and iOS.enter image description here

谷歌地图在加载脚本和触摸事件时开始出现错误。我将它用于 Android 和 iOS 上的cordova 应用程序。在此处输入图片说明

These are the errors I get but changing the load version didn't solve it.

这些是我得到的错误,但更改加载版本并没有解决它。

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MYKEY&v=3.21&libraries=geometry,places"></script>

回答by Luca Rainone

Version 3.30+ is affected of this problem if there is a global var called Map.

如果有一个名为Map.

ex:

前任:

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOURKEYHERE&v=3&callback=init" async defer></script>
<script type="text/javascript">
    function init() {
        Map.go();
    }
    var Map = {
        go: function() {
            console.log("start engine");
        }
    };
</script>

We got this error:

我们收到了这个错误:

TypeError: a.prototype is undefined

类型错误:a.prototype 未定义

Renaming window.Mapthen everything goes fine.

重命名window.Map然后一切顺利。