Triggering autocomplete component's service call programatically

2,537 views
Skip to first unread message

DiExor

unread,
Nov 11, 2011, 7:59:08 AM11/11/11
to Google Maps JavaScript API v3
Hello,

I am interested to hear if it is possible to somehow programatically
trigger some sort of event on a google.maps.places.Autocomplete's
input field, which will cause Autocomplete component to re-initiate a
service call.
I know that google has its own Event abstraction.
But anyway I was trying to set input's field value via jQuery.val
method.
I've also used jQuery's trigger method for various events (like change/
click/focus) in order to initiate autocomplete to perform a service
call, but it doesn't trigger any of the events that google's
autocomplete component is attaching to the input field.

Does anybody knows if and how is this possible?

Thanks at advance!

DiTieM

unread,
Nov 12, 2011, 5:41:37 AM11/12/11
to google-map...@googlegroups.com
Try this:


var input = document.getElementByID( ... )

// create the autocomplete for the input
(...)

input.val = 'whatever' ;

google.maps.event.trigger( input, 'focus', {} )


Problems:
- For some reason it does not always work (1 in 1000 times it does not request the service)
- Sometimes happens to get the suggestions of the previously introduced string

Good coding!

DiExor

unread,
Nov 14, 2011, 5:47:06 AM11/14/11
to Google Maps JavaScript API v3
Hi DiTieM,

Thanks for your response. That is exactly what I needed.

Regards!
Reply all
Reply to author
Forward
0 new messages