Reputation: 38
I'm using Ionic 3 and in a page in need to follow the position of the user ( only latitude and longitude ). How can I know if GPS is enable or not and how can I know if the user disable GPS through the android control panel ?
This is my code :
this.geolocation.watchPosition({enableHighAccuracy : true,maximumAge:0}).filter((p: any) => p.code === undefined).subscribe((position: Geoposition)=>{
this.latitude = position.coords.latitude;
this.longitude = position.coords.longitude;
});
Upvotes: 0
Views: 842
Reputation: 465
use android permissions https://ionicframework.com/docs/native/android-permissions/
this.geolocation.watchPosition({enableHighAccuracy : true,maximumAge:0}).filter((p: any) => p.code === undefined).subscribe((position: Geoposition)=>{
this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.ACCESS_COARSE_LOCATION).then(
result => console.log('Has permission?',result.hasPermission),
err => this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.ACCESS_COARSE_LOCATION)
);
this.latitude = position.coords.latitude;
this.longitude = position.coords.longitude;
});
Upvotes: 2