I am writing an application that uses geolocation. Everything works perfectly on the web and Android. However, on ios, I cannot fetch location (the second method that I have implemented - pick a location from the map works though)
I am getting this error in Xcode console:
⚡️ To Native -> Geolocation getCurrentPosition 7620184
ERROR MESSAGE: {"errorMessage":"The operation couldn’t be completed.
(kCLErrorDomain error 0.)","message":"The operation couldn’t be completed.
(kCLErrorDomain error 0.)"}
This is my method which fetches location:
private locateUser() {
if (!Capacitor.isPluginAvailable('Geolocation')) {
this.showErrorAlert();
return;
}
this.isLoading = true;
Plugins.Geolocation.getCurrentPosition()
.then(geoPosition => {
const coordinates: Coordinates = {
lat: geoPosition.coords.latitude,
lng: geoPosition.coords.longitude
};
this.createPlace(coordinates.lat, coordinates.lng);
this.isLoading = false;
})
.catch(err => {
this.isLoading = false;
this.showErrorAlert();
});
}
Do you have any idea what may cause this?
I ran into the same issue. In the Simulator clicking Features > Location > Custom Location and setting a location there fixed the issue for me. Hope this helps!