【发布时间】:2013-12-22 19:25:37
【问题描述】:
我有兴趣实现一个带有“提交”/“开始”按钮的 Google 地图搜索按钮(例如在 http://maps.google.com 上)。如果我在搜索框中按 Enter,一切都会很好,但我不知道如何使用按钮强制/提交搜索。
现在我的代码基于以下示例:https://developers.google.com/maps/documentation/javascript/examples/places-searchbox。最重要的部分是我现在正在使用它:
HTML:
<div id="intro-search">
<input id="search-box" />
<button type="button">Submit!</button>
</div>
JS:
// Listen for the event fired when the user selects an item from the
// pick list. Retrieve the matching places for that item.
google.maps.event.addListener(searchBox, 'places_changed', function() {
// ...
// Show the results on the map
// ...
}
我不知道如何在单击按钮时触发相同的事情。
另一方面,SearchBox 和 Autocomplete 控件之间有什么区别?他们不做同样的事情吗?
【问题讨论】:
标签: javascript google-maps google-maps-api-3