Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,297 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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