Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autocomplete on ios doen not work #1

Open
ghost opened this issue Jan 5, 2017 · 2 comments
Open

autocomplete on ios doen not work #1

ghost opened this issue Jan 5, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented Jan 5, 2017

Hi,
Autocomplete on ios doen not work. It is not possible to select the address in the result.
I searched for a solution but none so far. Here are some links to usefull solutions, but none refering to ionic 2 and typescript.
ionic-team/ionic-framework#1798
https://forum.ionicframework.com/t/google-autocomplete-place-changed-doesnt-trigger-on-ios-only/51442/7

@ghost
Copy link
Author

ghost commented Jan 7, 2017

I got the solution. This one works with the ion-searchbar.
Replace the autocomplete:

autocomplete() {
this._loader.load().then(() => {
let autocomplete = new google.maps.places.Autocomplete(this.searchbar.nativeElement.querySelector('.searchbar-input'), {
types: ["geocode"]
});
autocomplete.addListener("place_changed", () => {
this.zone.run(() => {
//get the place result
let place: google.maps.places.PlaceResult = autocomplete.getPlace();

                //set latitude, longitude and zoom
                this.map.lat = place.geometry.location.lat();
                this.map.lng = place.geometry.location.lng();
                this.map.zoom = 12;
                console.log(place);
                Keyboard.close();
            });
        });
    });
}

add the refernce to ElementRef
import { ElementRef } from '@angular/core';

Add this:
@ViewChild('searchbar', {read: ElementRef}) searchbar: ElementRef;

In map.html use:
<ion-searchbar color="primary" id="autocomplete" type="text" name="title" [formControl]="searchControl" #searchbar placeholder="search....">

Reference:
ionic-team/ionic-framework#7223

https://forum.ionicframework.com/t/getelementbyid-ion-input/43920/10

@yuhueilee
Copy link

You can also use:
@ViewChild(IonSearchbar, {static: false}) searchBar: IonSearchbar;
and place the following in ngAfterViewInit():
this.searchBar.getInputElement().then(input => {const autocomplete = new google.maps.places.Autocomplete(input, { types: types });})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant