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

Geolocation using Xamarin.Forms.Labs in a PCL project

$
0
0

Hello guys,

After browsing almost all the threads about Xamarin.Forms.Labs and Geolocator to get the current location and to use it in a Xamarin.Forms.Maps, i'm about to give up. And i'm quite lost when i see the Geolocation sample of Xamarin.Forms.Labs. As you may guess, i'm a newbie in Xamarin.

I've installed Xamarin.Forms.Labs 1.2.1-pre2 in the PCL, iOS and Android projects via NuGet.

I tried a few codes to make it works, but i'm always blocked by something. For example, i tried the sample code from this post, so i have this code :

    public async void test() {
        IGeolocator geolocator = DependencyService.Get<IGeolocator>();

        Xamarin.Forms.Labs.Services.Geolocation.Position result = null;

        if (geolocator.IsGeolocationEnabled) {
            try {
                if (!geolocator.IsListening)
                    geolocator.StartListening(1000, 1000);

                var task = await geolocator.GetPositionAsync(10000, CancellationToken.None);

                result = task;
            }
            catch (Exception e) {
                System.Diagnostics.Debug.WriteLine ("Error : {0}", e);
            }
        }
    }

But i got theses errors :

  • Error CS4033: The await' operator can only be used when its containing method is marked with theasync' modifier (CS4033) => I fixed it by using the code in an async method, but is there an alternative ?
  • Error CS0103: The name `CancellationToken' does not exist in the current context (CS0103) => Maybe i missed something for that ...

Could anyone help me ?

Thank you !

William.


Viewing all articles
Browse latest Browse all 58056

Trending Articles