Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How to Get latitude and longitude using Essentials

$
0
0

i'm trying to get lat and long using Xamarin.Essentials package but i'm getting an exception says"exception: this functionality is not implemented in the portable version of this assembly. you should reference the nuget package from your main application project in order to reference the platform-specific implementation. at xamarin.essentials.geolocation.platformlocationasync"
i installed the package to every platform

here's my code:

    private async void Button_Clicked(object sender, EventArgs e)
    {
        try
        {
            var request = new GeolocationRequest(GeolocationAccuracy.Medium);
            var location = await Geolocation.GetLocationAsync(request);

            if (location != null)
            {
                latitude.Text = location.Latitude.ToString();
                longitude.Text = location.Longitude.ToString();
            }
        }
        catch (FeatureNotEnabledException fnex)
        {

        }
        catch (PermissionException perex)
        {

        }
        catch (Exception ex)
        {
            await DisplayAlert("Error3", ex.ToString(), "ok");
        }
    }

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>