Google maps API:无法读取未定义的属性"__e3_"

Bib*_*ath 29 javascript google-maps-api-3

这是我正在添加的监听器 -

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);
            }
        });
    });
Run Code Online (Sandbox Code Playgroud)

但它在控制台中生成此错误 -

Uncaught TypeError: Cannot read property '__e3_' of undefined
Ke
Ie
R.addListener
(anonymous function)
Run Code Online (Sandbox Code Playgroud)

试过搜索.但没有解决方案.

小智 51

将您的监听器移动到初始化函数中.

  • 这应该是评论吗? (11认同)

ple*_*xer 9

只用一小部分代码很难说,但听起来好像找不到"地图".

您的地图变量不是全局的,或者以某种方式可由该代码访问,或者地图未使用以下内容创建:

map = new google.maps.Map(....)
Run Code Online (Sandbox Code Playgroud)

在尝试添加新的单击侦听器之前.