我有一个问题,包括Google Places API。我已经使用API密钥设置了所有内容,列表/建议正常,但place_changed
事件在我选择建议时未被触发。Google Places API:place_changed没有解雇
检查小提琴:https://jsfiddle.net/xj2d77be/3/
它应该工作,但我绝对不知道为什么它没有。
代码段(从发布小提琴):
$(document).ready(function() {
var autocomplete = new google.maps.places.SearchBox(document.getElementById('mapLocation'));
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
console.log(place);
});
console.log("Initialized")
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maps.google.com/maps/api/js?libraries=places"></script>
<input type="text" id="mapLocation" />
谢谢!但我不知道为什么“SearchBox”不起作用。我从Google那里找到一个样本,它们也使用SearchBox - 带有“places_change”状态。 –
@KevinLieser关注此链接,https://developers.google.com/maps/documentation/javascript/examples/places-searchbox –
这就是我所说的页面:正如你所看到的,他们启动'var searchBox = new google。 maps.places.SearchBox(输入);' –