In my Ionic 2 project, I have a class structured like the one below. Instead of using the Ionic Native geolocation plugin, I am working with the locationServices plugin.
export class LocationManager{
locationAcquiring:boolean;
locationAvailable:boolean;
constructor(){
this.locationAcquiring=true;
this.locationAvailable=false;
}
updateLocation(){
//Utilizing certain Cordova plugins to store latitude and longitude in local storage variables.
let self=this;
cordova.plugins.diagnostic.isLocationEnabled(function(enabled){
let selfA=self;
cordova.plugins.diagnostic.isLocationAvailable(function(available){
let selfB=selfA;
cordova.plugins.locationServices.geolocation.watchPosition(function(position) {
//Even though the project compiles without errors, the variable values are not getting updated here.
selfB.locationAcquiring=false;
selfB.locationAvailable=true;
},function(error){});
},function(error){});
},function(error){});
}
displayLocationValues(){
console.log(this.locationAcquiring);
console.log(this.locationAvailable);
}
}
The changes made within the locationServices plugin do not seem to reflect on the class variables.
Result from the displayLocationValues()
function:
true
false