0

I'm working on a .NET MAUI application to obtain the user's current location on an iPhone using Geolocation and Geocoding APIs. However, I'm facing an exception when trying to geocode the current location, which occurs only on iOS version 18 and not on iOS 17 and lower. I have also ensured that permissions are correctly set in the Info.plist file. The exception details are as follows when calling Geocoding.GetPlacemarksAsync()

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;
     } }

1 Answer 1

0

Here are couple of things you may consider,

  1. You didn't mentioned whether you are trying this in simulator or real device, If you are trying this in simulator then you need to set location of the particular simulator(iOS 18).

You can find how to set this here..

  1. The Geocoding.GetPlacemarksAsync() call requires Network connection. So, make sure whether the iOS 18 device/simulator you are trying this have a stable Network connection.
  2. Since you mentioned this works on iOS 17, Both the devices are in same location? If not, That means simply iOS can't reverse geocode your iOS18 device location. You can put the call in a try catch to handle this scenario.

Maui Essentials don't do anything additional, It directly submits code through iOS API. Check here..

Sign up to request clarification or add additional context in comments.

2 Comments

I am using an iPhone with iOS version 17 and lower, and everything is working as expected. However, when I try on an iPhone with iOS version 18, an exception occurs when calling Geocoding.GetPlacemarksAsync(). The error message is: Foundation.NSErrorException: Error Domain=kCLErrorDomain Code=2 "(null)" at the method Microsoft.Maui.Devices.Sensors.GeocodingImplementation.GetPlacemarksAsync(Double, Double).
var placemarks = await Geocoding.GetPlacemarksAsync(38.8977, -77.0365); This gives me loaction of White House as expected in iOS 18. So, Check what are the longitude, latitude values you are receiving from Geolocation.GetLocationAsync();. And, Posting same question as comment doesn't give a solution. Have you made sure/read all the things I suggested?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.