Javascript Google 地图 API:无法读取未定义的属性“__e3_”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7058094/
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
Google maps API: Cannot read property '__e3_' of undefined
提问by Bibhas Debnath
Here is the Listener I'm adding -
这是我要添加的监听器 -
var map;
var geocoder;
function initialize() {
var myOptions = {
zoom: 8,
center: new google.maps.LatLng(22, 88),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
}
//google.maps.event.addDomListener(window, 'load', initialize);
google.maps.event.addListener(map, 'click', function(event) {
geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'latLng': event.latLng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
alert(results);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
});
But it is generating this error in console -
但它在控制台中产生了这个错误 -
Uncaught TypeError: Cannot read property '__e3_' of undefined
Ke
Ie
R.addListener
(anonymous function)
Tried searching. But got no solution.
尝试搜索。但没有得到解决。
回答by Danny Hoek
Move your listener into the initializer function.
将您的侦听器移动到初始化函数中。
回答by plexer
It's hard to tell with only a small part of your code, but that sounds like it cannot find "map".
仅用一小部分代码很难判断,但这听起来像是找不到“地图”。
Either your map variable is not global, or somehow accessible by that code OR the map was not created with:
您的地图变量不是全局变量,或者该代码以某种方式可访问,或者地图不是通过以下方式创建的:
map = new google.maps.Map(....)
before you try and add a new click listener.
在您尝试添加新的点击侦听器之前。
回答by Adam
I don't know if this may be an issue for you since we don't see the part of your code where you are linking to the google maps library, but I just discovered the reason I was getting this error was from trying to include the "visualizations" library. Luckily I didn't need to use it anymore.
我不知道这对你来说是否是一个问题,因为我们没有看到你链接到谷歌地图库的代码部分,但我刚刚发现我收到这个错误的原因是试图包括“可视化”库。幸运的是,我不再需要使用它了。
I had this:
我有这个:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=geometry,visualization&sensor=true"></script>
and changed it to this:
并将其更改为:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=geometry&sensor=true"></script>
I no longer get the e3error.
我不再收到e3错误。
By the way, this error for me was not consistent and I could not figure out howto replicate it. I had to sit there and hit refresh over and over until the error occurred.
顺便说一下,这个错误对我来说是不一致的,我不知道如何复制它。我不得不坐在那里一遍又一遍地刷新,直到发生错误。
I hope this helps someone.
我希望这可以帮助别人。
回答by NoWomenNoCry
In my case it was that the global map variable had been overwritten in the initializer but I wanted to use that global variable in another function and this caused the problem.
在我的情况下,全局映射变量已在初始化程序中被覆盖,但我想在另一个函数中使用该全局变量,这导致了问题。
回答by Hatzegopteryx
This happens when loading your data asynchronous. You can avoid that by including your document.ready code into the ajaxStop function
异步加载数据时会发生这种情况。您可以通过将 document.ready 代码包含到 ajaxStop 函数中来避免这种情况
$().ready(function() {
$(document).ajaxStop(function () {
/* your code here ?*/
});
});
回答by Thoughtful Monkey
Something like this?
像这样的东西?
var lati,longt; //contains latitude and longitude
func newLatLOng(){
get new value of latLong
initMap();
}
var map = 0;
function initMap() {
if (map ===0)
{
//load first time
lati= 28.5072216;
longt= 77.4971153;
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: lati, lng: longt},
zoom: 13
});
}else
{
var geolocation = { lat:lati,
lng: longt };
google.maps.event.trigger(map, 'resize');
map.setCenter(geolocation);
}
回答by User-8017771
In my case google.maps.event.addListener(marker, 'click', function() {The marker variable was undefined. And hence the error. Might be useful for someone.
在我的情况下 google.maps.event.addListener(marker, 'click', function() {,标记变量未定义。因此错误。可能对某人有用。
回答by Magnus Melwin
Yes, second that... The map variable must be declared outside and before its use. As the google maps listener cannot find it.
是的,其次... map 变量必须在使用之前和外部声明。由于谷歌地图侦听器找不到它。

