3

I also tried to trigger the event

google.maps.event.trigger(autocomplete, 'place_changed');

but autocomplete.getPlace() is still return undefined until I change the city manually.

Any suggestions please?

Zolyboy
  • 457
  • 7
  • 17

1 Answers1

3

From google docs: getPlace(): Returns the details of the Place selected by user if the details were successfully retrieved. Otherwise returns a stub Place object, with the name property set to the current value of the input field.

Using for example the following code:

    var autocompleteSearch = new google.maps.places.Autocomplete(searchField, searchOptions);

    setInterval(function() {
        var place = autocompleteSearch.getPlace();
        console.log('place: ');
        console.log(place);
    }, 5000);

you will get 'undefined' in console if you wrote for example "qwertyasdfgh". Until you press Enter: after that the result will be:

place:  
Object {name: "qwertyasdfgh"} 

So, it's not much useful. No address_components, geometry...

Anto Jurković
  • 11,188
  • 2
  • 29
  • 42
  • Thank you for the answer... I'm slightly disappointed, cause i have to implement another autocomplete then... – Zolyboy Apr 17 '14 at 11:59