Позиция не определено Ионная 4 Геолокация - PullRequest
0 голосов
/ 27 апреля 2019

У меня ошибка при попытке показать карту на моей странице, я думаю, потому что я использую ionic 4, и я пытался передать код из одного приложения с более старой версией

консоль выдаёт мне следующую ошибку (на рисунке)

Я попытался запустить приложение в эмуляторе AVD, на физическом устройстве с Cordova и с ионной подачей, но карта нигде не отображается

Это мой код:

constructor(public afAuth:AngularFireAuth, public geolocation:Geolocation) {

}

ngAfterViewInit() {
    this.getPosition();
}

getPosition():any {
    this.geolocation.getCurrentPosition().then(response => {
       this.loadMap(response);
    }).catch(error => {
      console.log(error);
    });
}


loadMap(position: Geoposition) {
    this.latitude = position.coords.latitude;
    this.longitude = position.coords.longitude;
    console.log(this.latitude, this.longitude);

    // create a new map by passing HTMLElement
    const mapEle: HTMLElement = document.getElementById('map');

    // create LatLng object
    const myLatLng = {lat: this.latitude, lng: this.longitude};

    // create map
    this.map = new google.maps.Map(mapEle, {
      center: myLatLng,
      zoom: 12
    });

    google.maps.event.addListenerOnce(this.map, 'idle', () => {
        const marker = new google.maps.Marker({
          position: myLatLng,
          map: this.map,
          title: 'AQUI ESTOY!'
        });
        mapEle.classList.add('show-map');
    });
}

Это ошибка, которая отображается на консоли:

25.7280391 -100.3622132 ingresar.page.ts:47:4
TypeError: "a is null"
Ge (index):71
eh (index):110
loadMap ingresar.page.ts:56
getPosition ingresar.page.ts:36
Angular 10
ingresar.page.ts:39:6
ERROR TypeError: "position is undefined"
loadMap ingresar.page.ts:45
View_IngresarPage_5 IngresarPage.html:27
Angular 13
IngresarPage.html:27:4
View_IngresarPage_5 IngresarPage.html:27
Angular 12
ERROR CONTEXT 
Object { view: {…}, nodeIndex: 0, nodeDef: {…}, elDef: {…}, elView:       

{…} }
IngresarPage.html:27:4
...