I’m developing a .NET MAUI application where I’m trying to get the user’s current location using the Geolocation and Geocoding APIs. However, I’m encountering an exception when attempting to geocode the current location only happening to iOS 18 not in 17. The exception details are as follows:
Foundation.NSErrorException: Error Domain=kCLErrorDomain Code=2
“(null)” at
Microsoft.Maui.Devices.Sensors.GeocodingImplementation.GetPlacemarksAsync(Double,
Double) at
DiDe.CabManagement.ViewModels.CancelBookingViewModel.GetLocationAsync()var status = await
Permissions.CheckStatusAsync<Permissions.LocationWhenInUse>();if (status != PermissionStatus.Granted) {
// Request permission if it’s not already granted
status = await Permissions.RequestAsync<Permissions.LocationWhenInUse>(); }if (status == PermissionStatus.Granted) {
Location location = await Geolocation.GetLocationAsync();if (location != null) { var placemarks = await Geocoding.GetPlacemarksAsync(location.Latitude, location.Longitude); App.CurrentLocation = location; } }