Google Maps API:SearchBox不再有效了吗? [重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

搜索框上的事件监听器似乎不再起作用。在以下代码中,永远不会调用回调函数:

    var defaultBounds = new google.maps.LatLngBounds(
                  new google.maps.LatLng(41.982419, -5.165268),
                  new google.maps.LatLng(51.674259, 9.912761));
    var searchBox = new google.maps.places.SearchBox(document.getElementById('address'), {
          bounds: defaultBounds
    });
    google.maps.event.addListener(searchBox, 'places_changed', function() {
      console.log('Places', searchBox.getPlaces());
    })

即使在官方文档中,该示例也不起作用:https://developers.google.com/maps/documentation/javascript/examples/places-searchbox

这很奇怪,因为一周前这段代码还行。

API最近有变化吗?任何人都面临类似的问题?

javascript google-maps
1个回答
0
投票

如果您想要自动完成搜索框,可以使用此选项

https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete
© www.soinside.com 2019 - 2024. All rights reserved.