Using geolocation plugin with leaflet in ionic 3


#1

I am working on an app that display user’s position info (latitude,…) with ionic 3 to do that am using the geolocation plugin but I keep getting undefined variable here’s my code.

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;
}

what am i doing wrong here?