then it doesn’t quite work. When you start typing an address in a field the matching addresses appear ok in a drop down list but if I select one, the ion-item field is not populated. I’ve tried binding to a model and setting the value in the event listener but this won’t work. It seems like that event listener is not running. Any ideas how I might get this to work?
[UPDATE] - forgot to say that this (using ion-input) works ok in the browser, its only on a device that it doesn’t work.
I´ve been able to do an implementation using a modal to load the predictions (which is more user friendly than adding a dropdown to an input), you can follow the code in github https://github.com/guillefd/gmapsAutocomplete-RC1
var nativeHomeInputBox = document.getElementById('txtHome').getElementsByTagName('input')[0];
let autocomplete1 = new google.maps.places.Autocomplete(nativeHomeInputBox, searchOptions);
@Hollywood and @AkashM08 the key is that if you are using a segment (or anything that shows/hides based on template directives [*ngIf, *ngSwitchCase, etc.] you need to remember that the DOM for those elements isn’t even created until you switch to that tab/segment - and if you LEAVE, the DOM elements are deleted.
You therefore need to handle your Google handles appropriately, adding and removing them as appropriate. E.g. to use a Google Places autocomplete with an input box on a second segment, you watch the segment change event and initialize the Autocomplete object after that point.
However, keep in mind that just capturing the change event isn’t enough: There is some time between the event and the DOM elements appearing, and while you can “guess” by using setTimeout, the better thing to do is to use ngAfterViewChecked directly from Angular, instead of the Ionic lifecycle events. Set a flag in the segment change handler, and in ngAfterViewChecked if that flag is true, re-init the Google component and then reset the flag to false.