geolocation plugin build and run first time then position error:application does not have sufficient geolocation permission occurs and when open app second time then no error
Just now realised that , it is working fine in Android version 5.1 .
But not working on Android version 6.0 .
Below is my code for get the country from the current location.
Sometimes , I got the array from geolocation which gave me country details…
Actual scenario is: if i run the app and location service is not enable then it just loading infinitely.
If i remove the app from task manager and reopen the app then i get the proper result. Location service also enabled.
Dont know why location service is not enable before geolocation gets currentpostion at first time.
these two function i have called in ionViewDidLoad().
requestAccuracy() {
this.locationAccuracy.canRequest().then((canRequest: boolean) => {
if(canRequest) { this.locationAccuracy.request(this.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY).then(() => {
console.log('Request successful.')
// this.closeModal();
},
error => {
console.log('Error requesting location permissions', error)
// this.closeModal();
}
);
}else{
// close the app .
this.plt.exitApp();
}
});
}
//requestAccuracy() ends
setCountryFromLocation() {
console.log("In setCountryFromLocation");
let loading = this.loadingController.create({content : "Loading,please wait..."});
var options = {
enableHighAccuracy: true
};
loading.present();
this.geolocation.getCurrentPosition(options).then((position) => {
this.nativeGeocoder.reverseGeocode(position.coords.latitude, position.coords.longitude)
.then((result: NativeGeocoderReverseResult) => {
loading.dismissAll();
if(result!=undefined){
var obj;
var country;
this.myOb.countryName = result.countryName;
}else{
// alert for not getting reverseGeocode
console.log(JSON.stringify(result));
}
})
.catch((error: any) => {console.log(error)
loading.dismissAll();
});
}, (err) => {
console.log(err);
loading.dismissAll();
}
);// geolocation ends
}//setCountryFromLocation () ends