Can't get location

Hi,

I'm using Xamarin.Mobile to get the curernt location for the device. I have read the it does not work in the simulator.
Now I have testet it on a device (IOS 9.1)

But with no luck.
The GetPositionAsync never returns.

`public async Task GetCurrentLocation()
{
var locator = new Geolocator { DesiredAccuracy = 50 };
var cancelSource = new CancellationTokenSource();
var location = GeoLocation.Undefined;

        await locator.GetPositionAsync(1000, cancelSource.Token).ContinueWith(
            t => location = t.IsCompleted 
                ? new GeoLocation(t.Result.Latitude, t.Result.Longitude) 
                : GeoLocation.Undefined, 
            cancelSource.Token);

        return location;
    }`

Anyone that knows what to do?

Br Morten

Tagged:

Best Answers

Answers

  • Hello all!

    Similar problem here

  • Yes, I have already tried this. But with no luck.

    var position = await locator.GetPositionAsync(10000);

    never returns

  • Antonio.2859Antonio.2859 USMember

    the same problem, how do you solve it Morten?
    when i call from my pcl project var position = await locator.GetPositionAsync(10000); it never returns...

  • RenaudLaloireRenaudLaloire BEUniversity ✭✭

    Hey, same problem here.

    I'm sending a silent remote notification to wake up the device, get his location using locator.GetPositionAsync but this method never returns.

    All the config like UIBackgroundModes key, allowsBackgroundLocationUpdates and NSLocationAlwaysUsageDescription is OK.

    Anyone on this?

    Thank you

  • DamienRamseyDamienRamsey IEUniversity ✭✭
    edited May 2016

    Has anyone ever got a solution for this ?
    Im in android and pushed it out to a class... but never returns :neutral:
    No errors etc....

    public async Task GetLocationAsync() ..... var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 1000; if (locator.IsGeolocationEnabled){ position = await locator.GetPositionAsync(20000); }

    called from separate class
    using(DeviceLocation deviceLocation = new DeviceLocation(globalContext)) { await deviceLocation.GetLocationAsync(); current_Lat = deviceLocation.current_Lat(); current_Lng = deviceLocation.current_Lng(); }

    Now the funny thing is :sweat_smile:
    If i put code on my main cs as per example code on git (link above in other comment) it works no problems....

    Its as if its not awaiting or something else is going on ..

  • AtishooMazumderAtishooMazumder USMember ✭✭

    Using GeoLocator Plugin Version 3.0.4 (Stable) and 4.0.* Beta targeting Android 7.1.
    Its unable to fetch location using Stable (3.0.4) Plugin Version. But with beta version of Plugin its giving "Could not resolve type with token 010001fe" xamarin.geolocator. But Plugin is working fine for Lower target versions.

  • kmalkmal ARMember

    try this var position = await locator.GetPositionAsync(timeout: new TimeSpan(10000));

  • NiteshLuharukaNiteshLuharuka USDeveloper Group Leader ✭✭
    edited November 2017

    This works like a charm - var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(10000), null, true);

  • BFaruqiBFaruqi USMember

    Thanks Nitesh
    For the latest stable verison 4.1.3 this work like you said.
    var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(10000), null, true);

  • LarryKenobiLarryKenobi USMember ✭✭

    I had this working then tried to make some unit tests to test my class that uses Geolocator. It is in an android test runner with the proper nuget packages and this just refuses to work. It didn't work originally in my project but something fixed it.

    Why can't I just get the position?

Sign In or Register to comment.