Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

GetPositionAsync always cancelling task #16

Open
ermau opened this issue Oct 9, 2013 · 14 comments
Open

GetPositionAsync always cancelling task #16

ermau opened this issue Oct 9, 2013 · 14 comments

Comments

@ermau
Copy link
Member

ermau commented Oct 9, 2013

Originally submitted by @georgepiva on issue #6

Xamarin.Geolocation.Geolocator geolocator = new Xamarin.Geolocation.Geolocator (context);
geolocator.GetPositionAsync (timeout: 6000).ContinueWith (task => { // task.IsCanceled is always equal to true. });

I can see this happening on both Xamarin.Mobile component 0.6.3 and 0.7 versions. It also happens when downloading the master branch of this repository as a Zip file and importing it inside my project.

I have just tried to run the GeolocationSample project on a Samsung Galaxy S3 and got the same results:

screenshot_2013-10-03-15-00-52

My beta testers are also notifying me about this localization issue and they are using different devices from me.

@ermau
Copy link
Member Author

ermau commented Oct 9, 2013

Have you tried longer timeouts or a different DesiredAccuracy? I noticed you're not setting your DesiredAccuracy in your example.

I was not able to reproduce this error with any of the Galaxy S3 or S4 variants.

@georgepiva
Copy link

Hi @ermau.

I have just tried using different values:

public const int Timeout = 30 * 1000; // 30s
public const double DefaultAccuracy = 500000; // 500 km

instead of my default ones:

public const int Timeout = 6 * 1000; // 6s
public const double DefaultAccuracy = 2000; // 2 km

but the result still the same.

One thing that is making me confused is that this morning, one of my beta testers installed my app and all localization features were working inside his Samsung Galaxy S3. I am now wondering why it is happening inside some devices (including mine) and not happening inside others.

I have double checked the Location configurations inside my device:

  • Settings App -> Location Services -> All ON;
  • Settings App -> Accounts -> Google -> Location Settings -> Let Google apps access you location -> ON;
  • Google Settings App -> Location -> Google location settings -> All ON.

By turning some of them off I received an error from the component which is right, but when turning then back to on I restarted receiving a canceled task.

Am I missing to check something inside my device?

@georgepiva
Copy link

It is unbelievable I was two weeks without restarting my device. Right after restarting it, all localizations features started to work again. It appears to be an Android Bug.

@ermau
Copy link
Member Author

ermau commented Oct 9, 2013

It is unbelievable I was two weeks without restarting my device. Right after restarting it, all localizations features started to work again. It appears to be an Android Bug.

Were geolocation services working in any other app before you restarted it though?

@georgepiva
Copy link

Yes, I was able to use both Google Maps application and the Google Play Services Rev. 12 component (inside my app). Maybe because of this I did not think about restart the device.

@ermau
Copy link
Member Author

ermau commented Oct 9, 2013

Yes, I was able to use both Google Maps application and the Google Play Services Rev. 12 component (inside my app), maybe because of this I did not think about restart the device.

So either there's a bug in XM or there's a bug in Android and Google is cheating somehow. Hard to really narrow down at this stage.

@georgepiva
Copy link

Yes, the good point is that it is not a blocker issue anymore, I am now able to publish my Android App this weekend. I am going to try to figure it out how can I reproduce the problem on my device and then I can return and post the results here. But thank in advance @ermau for the support.

@georgepiva
Copy link

Hi @ermau. I am writing to you this time because I have lots of users complaining about not having their location found by my application and so their are given bad rates to it. Others that didn't face this issue are always given good rates. Whenever I can I am answering them to restart their devices and so, hopefully, they will be able to use the app. Did you see somebody else facing this problem as well? I really need at least a workaround to this issue. May you share some thoughts with me? Maybe I need to start using a geoip service or try to use some native Android API to get current users location? What would you do? If you would like to try using my app, I can share its Google Play url. Thanks in advance.

@georgepiva
Copy link

Hi @ermau, look to this thread: https://code.google.com/p/android/issues/detail?id=57707 it may be the reason for this problem.

@ermau
Copy link
Member Author

ermau commented Dec 10, 2013

Hi @ermau, look to this thread: https://code.google.com/p/android/issues/detail?id=57707 it may be the reason for this problem.

It seems like I was right originally, it appears to be a bug in the built in location providers and Google is using a completely different one via Google Play Services. I would recommend giving Google Play Services a shot and seeing if that solves your issue. If the built in stuff is going to continue to fail, we may have to switch X.M to use it as well.

@qmatteoq
Copy link

Hi, is there any update on this issue? I'm getting the same exact error in a Xamarin Forms project on Windows Phone: I've created a wrapper class in the Windows Phone project that simply retrieves the user's position using Xamarin Mobile.

public async Task<Position> GetPositionAsync() { Geolocator locator = new Geolocator(); if (locator.IsGeolocationAvailable && locator.IsGeolocationEnabled) { var position = await locator.GetPositionAsync(10); return new Position {Latitude = position.Latitude, Longitude = position.Longitude}; } return null; }

Then, by using the DependencyService, I retrieve the instance of my wrapper in the PCL shared project: however, whenever I launch the application on Windows Phone and I call the GetPositionAsync() method of the Geolocator class, I get a "TaskCanceledException - A task has been canceled".

@supreettare
Copy link

https://gist.github.com/supreettare/0433e34f9fdf4d750bb2

This code fixes the TaskCancelledException on android. After rewriting the code this way, I never got the exception again.

@rdeepakmse
Copy link

@supreettare Can you post the sample of your project? Even I am trying to create a Dependency service to access the co-ordinates to process without displaying the data on the UI for android devices...

@antoniopicardi
Copy link

please @supreettare , can you post the same of your project? thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants