question

UniversalCamera-5217 avatar image
0 Votes"
UniversalCamera-5217 asked JarvanZhang-MSFT commented

GPS location not working with device inside a pocket

I have a Xamarin.Forms SMS based app that works great in Background using WakeLock while the device is sitting turned off on a table. Even when the device is turned off I can get the device location from another device. However, as soon as I put the device in my pocket then I get NoGPS response. Same NoGPS behavior if the proximity sensor is covered or there is total darkness. In total darkness I see device being woken while retrieving GPS Coordinates but listener returns null.

             await CrossGeolocator.Current.StartListeningAsync(TimeSpan.FromSeconds(5), 5, true, null);

I am waking the device using

         var PM = (PowerManager)this.GetSystemService(Context.PowerService);
         WL = PM.NewWakeLock(WakeLockFlags.Full | WakeLockFlags.AcquireCausesWakeup, "Mom");

I have tried adding different WakeLockFlags but no success.

Again the App works great outside of the pocket or not in darkness.

Thank you

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered JarvanZhang-MSFT commented

Hello,​

Welcome to our Microsoft Q&A platform!

I see device being woken while retrieving GPS Coordinates but listener returns null.

Hi, UniversalCamera. I create a basic demo to get the location inside a pocket, it works as expected. I use the CrossGeolocator.Current.GetLastKnownLocationAsync method to get the position value. How did you do that? Do you get the value via the PositionChanged event? Try to test the function on other brand devices to check if it is caused by the device.

If the issue also occurs on other devices, could you please post the related function code? It'll help to reproduce the issue.

Best Regards,

Jarvan Zhang



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you

I apologize for lack of my understanding!!!!!

My understanding is that GetLastKnownLocationAsync is tapping "Last-Fused-Location" of device from multiple internal resources? But, since I don't let any apps run in background (except for mine) GetLastKnownLocationAsync will produce a very old data. So based on that (stupid?) logic I elected to use StartListeningAsync which returns NULL as stated earlier.

Regardless, why StartListeningAsync becomes debilitated under darkness or in-pocket?

Thank you!

0 Votes 0 ·

why StartListeningAsync becomes debilitated under darkness or in-pocket

Hi, did you test this function on other devices? Please test it to check if the issue is caused by the device.

0 Votes 0 ·

Thank you

I like to Mark your response as an Answer. My attempt to do that gave me the credit for my input. Not sure how to fix this. I tried deleting my answer?

I just wanted to add this to your suggested answer

Thank you

On Android 11 with Battery Saver Maximum there are no issues. So going back to Android 10 Maximum Battery Saver seems to be a problem for darkness. Not a desired Battery Savings but it seems to work under darkness.

Do you have some insight of how to Optimize and get GPS data in darkness.
Regardless Great Support!

Thank you!

0 Votes 0 ·
Show more comments