我有兴趣实施一个Google Maps搜索按钮,并在其旁边添加一个“ Submit” /“ Go”按钮(例如,在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,您必须像这样在输入字段上使用Google Map的触发事件
document.getElementById('my-button').onclick = function () {
var input = document.getElementById('my-input');
google.maps.event.trigger(input, 'focus', {});
google.maps.event.trigger(input, 'keydown', { keyCode: 13 });
google.maps.event.trigger(this, 'focus', {});
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句