TypeError: a is undefined in Google Maps geocoder

TypeError: a is undefined in Google Maps geocoder

我正在尝试创建一些代码,以允许在用户点击的任何地方弹出一个具有反向地理编码位置和国家/地区的信息窗口。 我实际上得到了反向地理编码部分的工作。然而,当摆弄代码时,它开始给出错误消息 "TypeError: a is undefined in Google Maps geocoder".

我已经尝试将代码恢复到它以前工作的位置,但我似乎无法让它再次工作。 删除整个功能不会做任何事情; geocoder.geocode({'location': latLng}) 立即给我错误信息。 我检查了输入地理编码器的纬度和经度是否正确。

var map;

    //initialize the map
    function initMap() {
        map = new google.maps.Map(document.getElementById('map'), {
            center: {
                lat: 0,
                lng: 0
            },
            zoom: 2
        });
    }

    initMap();



    function placeMarker(latLng, map) {
        //place marker
        var marker = new google.maps.Marker({
            position: latLng,
            map: map
        });


        //reverse geocode marker location
        var geocoder = new google.maps.Geocoder;

        geocoder.geocode({'location': latLng}), function(results, status) {
                ...
                };

            };
        ...

    //tie placing markers and opening info windows to the mouse click
    map.addListener('click', function(e) {
        placeMarker(e.latLng, map);

    });

) 的位置不正确。在 ...cation': latLng} 之后您将关闭参数列表,因此您尝试作为回调传递的函数声明语法错误。在 ...cation': latLng} 之后将你 ) 移动到回调的末尾。像这样:

geocoder.geocode({'location': latLng}, function(results, status) {
    ...
})