gpt4 book ai didi

android - 无法读取未定义的属性 'latitude'

转载 作者:行者123 更新时间:2023-11-30 00:25:00 26 4
gpt4 key购买 nike

我正在试用 ionic native。获取权限成功,但之后报错cannot read property 'latitude' of undefined

注意* 我使用的是 android 模拟器,而不是物理设备。

    import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { Geolocation } from '@ionic-native/geolocation';
import { AndroidPermissions } from '@ionic-native/android-permissions';

export class GeolocationPage {

latitude: number;
longitude: number;

constructor(private platform: Platform, private geolocation: Geolocation, private androidPermissions: AndroidPermissions) {

this.platform.ready().then(() => {

this.androidPermissions.requestPermissions([this.androidPermissions.PERMISSION.ACCESS_COARSE_LOCATION]).then(
sucess => this.onSucess(),
err => this.onFailure()
);

});
}

onSucess(){
alert('onSucess');

this.geolocation.watchPosition().subscribe(pos => {
this.latitude = pos.coords.latitude;
this.longitude = pos.coords.longitude;
});
}

onFailure(){
alert('onFailure');
}
}

最佳答案

 onSucess(){
alert('onSucess');
let _me = this
this.geolocation.watchPosition().subscribe(pos => {
_me.latitude = pos.coords.latitude;
_me.longitude = pos.coords.longitude;
});
}

关于android - 无法读取未定义的属性 'latitude',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45561477/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com