打字稿中的未定义变量?

时间:2018-04-06 10:56:31

标签: javascript ionic3 w3c-geolocation

我正在开发一个应用程序,显示用户的位置信息(纬度,...)和离子3来做这个使用地理定位插件,但我一直得到未定义的变量这里是我的代码。

posit(){
    this.geolocation.watchPosition({enableHighAccuracy:true}).subscribe((data)=>{
        this.latitude=data.coords.latitude;
        this.longitude=data.coords.longitude;
        this.altitude= data.coords.altitude;
        console.log("geolocalisation");
        this.prec=data.coords.accuracy;
        this.speed=data.coords.speed;
        this.timestamp=this.time_stamp(data.timestamp);
        this.testvar=[data.coords.latitude,data.coords.longitude];
        console.log(this.prec)//i get the true value 
    });
    console.log(this.prec)//i get undefined
    return this.testvar;
}

我在这里做错了什么?

0 个答案:

没有答案