Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google map api v3: SearchBox. Emulating press Enter button

When you enter some text in SearchBox it will show you a drop-down with a few choices but if you instead press Enter button it will return most corresponding answer immediatelly.

How to achieve this behavior programatically?

I tried to emulate press Enter event on this control and calling .getPlaces() method manually but nothing happens.

Is there any solution for this problem?

like image 461
kharandziuk Avatar asked Feb 25 '26 03:02

kharandziuk


1 Answers

It seems that the listeners for the searchBox will be bound on focus and removed on blur.

So you must first trigger the focus-event and then the keydown-event of the input associated with the searchBox.

When you trigger the keydown-event, pass as argument an object with the property keyCode:13

//input associated with the searchBox
var input = document.getElementById('pac-input');

google.maps.event.trigger( input, 'focus')
google.maps.event.trigger( input, 'keydown', {keyCode:13})
like image 104
Dr.Molle Avatar answered Mar 04 '26 15:03

Dr.Molle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!