Ionic - Google places and Autocomplete location

后端 未结 3 458
北恋
北恋 2020-12-08 14:51

I have work on the project on Ionic 2 and I have implemented the map so far, but I can not get out of that point. I needed to be shown the way I should go in order to add Go

3条回答
  •  遥遥无期
    2020-12-08 15:05

    Use elementref for accessing the ion input used instead of document.getElementById Try:

     
    

    In your component class,

     import {Elementref } from '@angular/core'; 
     @ViewChild("places")
      public places: ElementRef;
        InitMap(){
        this.setLocation();
        let autocomplete = new google.maps.places.Autocomplete(this.places.nativeElement);
        google.maps.event.addListener(autocomplete, 'place_changed', () => {
    
            let place = autocomplete.getPlace();
            this.latitude = place.geometry.location.lat();
            this.longitude = place.geometry.location.lng();
            alert(this.latitude + ", " + this.longitude);
            console.log(place);
          });
    
        }
    

    Check angular docs here

提交回复
热议问题