I’m absolutely exhausted by trying to get the location of user using Geolocation plugin.
But the problem is that if the GPS is already connected before launching my app, it works, otherwise it never works.
Meaning that If turn on the location on device after launching my app, Geolocation plugin never works.
here is the code I’m trying
if (Capacitor.isPluginAvailable('Geolocation')) {
Plugins.Geolocation.getCurrentPosition().then(location => {
this.alertCtrl.create({
animated: true,
header: `Platform: ${Capacitor.getPlatform()}`,
subHeader: 'Coordinates: ',
message: `Latitude: ${location.coords.latitude}\n Longitude: ${location.coords.longitude}`
}).then(alertEl => alertEl.present());
}).catch(error => {
console.log('Error:', error);
this.alertCtrl.create({
animated: true,
header: `Error Occured`,
// subHeader: error,
message: error.message
}).then(alertEl => alertEl.present());
})
}
This is the simplest method and doing nothing anything rocket science.
How can I make my app to fetch the user location if the device GPS was disabled and user just enabled after launching my app.