从提交按钮触发Google地图中的places_changed [英] Trigger places_changed in Google maps from submit button
问题描述
我想在单击提交按钮时触发我的placed_changed
函数.所以这就是我所拥有的,我有一个searchbox
我使用google.maps.places.SearchBox
分配,一旦我单击Enter并使其焦点对准搜索框,它就会触发该事件:
I am wanting to trigger my placed_changed
function when a submit button is clicked. So here is what I have, I have a searchbox
I assign using google.maps.places.SearchBox
and once I click enter with the search box on focus it triggers the event:
google.maps.event.addListener(searchBox, 'places_changed', function() {
runMainPopulation(searchBox.getPlaces());
});
哪个运行下一个功能.现在,我想做的就是一旦单击search button
或单击searchbox
上的Enter,就可以运行此功能.
Which runs the next function. Now what I am trying to do is get this function to run once I click a search button
or I click enter on my searchbox
.
建议,想法?
推荐答案
我知道了.
我必须通过google method
帖子初始化Google searchBox
.
I had to initialize the Google searchBox
via google method
post.
例如:
$(".submit-search").bind('click', function() {
input.focus();
var e = jQuery.Event("keydown");
e.which = 13; // # Some key code value
$(input).trigger(e);
google.maps.event.trigger(searchBox, 'place_changed');
});
这行不通,我不确定为什么,但是不行. submit-search
是searchBox
旁边的按钮,也定义为input
.
This would not work, I am not to sure as to why but it doesn't. submit-search
is the button next to searchBox
also defined as input
.
现在,如果我初始化输入触发器焦点并单击google.maps.event.trigger
,它将非常完美:
Now if I initialize my input trigger focus and click through google.maps.event.trigger
it works perfect:
$(".submit-search").bind('click', function() {
google.maps.event.trigger(input, 'focus')
google.maps.event.trigger(input, 'keydown', {
keyCode: 13
});
});
这篇关于从提交按钮触发Google地图中的places_changed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!