question

JassimAlRahma-9056 avatar image
0 Votes"
JassimAlRahma-9056 asked JarvanZhang-MSFT commented

Problem in GetPlacemarksAsync

Hi,

I am trying to get the location from my ContentView in my app.


 async void GetLocation()
 {
     try
     {
         var request = new GeolocationRequest(GeolocationAccuracy.Default);
    
         var location = await Geolocation.GetLastKnownLocationAsync();
    
         if (location == null)
         {
             location = await Geolocation.GetLocationAsync(request);
         }
    
         latitude = location.Latitude;
         longitude = location.Longitude;
    
         **var placemarks = await Geocoding.GetPlacemarksAsync(latitude, longitude);**
         var placemark = placemarks?.FirstOrDefault();
    
         if (placemark != null)
         {
             country_code = placemark.CountryCode;
             country_name = placemark.CountryName;
         }
     }
     catch (FeatureNotSupportedException ex)
     {
         Crashes.TrackError(ex, new Dictionary<string, string>
         {
             { "Page", "HomePage" },
             { "Where", "GetLocation" }
         });
     }
     catch (Exception ex)
     {
         Crashes.TrackError(ex, new Dictionary<string, string>
         {
             { "Page", "HomePage" },
             { "Where", "GetLocation" }
         });
     }
 }



but the app is reaching to await Geocoding.GetPlacemarksAsync the existing to the next code although it returns the correct lat and long.

How can I fix this please?


Thanks,
Jassim

dotnet-xamarin
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, JassimAlRahma. Do you mean the Geocoding.GetPlacemarksAsync function takes a long time to perform the work? There is confusion about the problem, could you please post more details about the that?

0 Votes 0 ·

0 Answers