Strange GPS problem

Hello guys,

Just wonder if somebody have same or simmilar issue with GPS. I made an app more then a year back and used it daily on my Huawei P20 Pro. A part of that app is basic GPS location logging.

On P20PRO (android 10) app worked like a charm but now I switched to Xiaomi 11T Pro (android 12), add all required permissions but GPS data is not consistent.

That is how data were on P20Pro - speed (obd speed as reference):


location:

and thats how it looks now - speed (obd speed as reference):


location:

I tried different phone position, turned off all energy saving options, double check that precise location is allowed for app, but without any difference. Other apps like google fit have no issues with GPS.

All settings for GPS are default and I do collect data from it with a simple store to dictionary blocks…

blocks

Any idea what to check?

Best Regards, Alex

it looks like only coarse location permission has been granted
Taifun

That was also my first tought but no, it is set as needed:

br Alex

from your latest screenshot it looks like “Use precise location” is switched off…
EDIT: see also here Request location permissions  |  Android Developers

User can grant only approximate location

On Android 12 (API level 31) or higher, users can request that your app retrieve only approximate location information, even when your app requests the ACCESS_FINE_LOCATION runtime permission.

To handle this potential user behavior, don’t request the ACCESS_FINE_LOCATION permission by itself. Instead, request both the ACCESS_FINE_LOCATION permission and the ACCESS_COARSE_LOCATION permission in a single runtime request. If you try to request only ACCESS_FINE_LOCATION , the system ignores the request on some releases of Android 12. If your app targets Android 12 or higher, the system logs the following error message in Logcat:

ACCESS_FINE_LOCATION must be requested with ACCESS_COARSE_LOCATION.

it looks like our @Kodular team will have to provide a solution, so both permissions can be requested in a single runtime event… alernatively someone could write a short extension for that…

Taifun

On a screensot fine location is on. Same as on other apps where fine location works as it should.
Thank you for dig out the problem Kodular team needs to solve tat isusse as soon as possible as waiting for someone to write extension is no solution at all. I know your work, bought some extensions from you so perhaps you could write that short extension… would be pretty much like kodular solution :slight_smile: :slight_smile:

Best regards, Alex.

See the statement by MIT here

Taifun

1 Like

Thanks for link. As I do understand, there will be some solution later this month. I also tried what was suggested in above that MIT response and set up privilledge outside the screen init and that seems to solve a part of the problem as location is now fine. BUT… yeah there is always a BUT :slight_smile:

It is updated ike every minute or even less instead of every s…I tested with default 1000ms and some values up and down… nothing helped.

I also turned of all battery saving options… Hope till end of august all that will dissapear… or I will need to swithc to older phone for that purpose :slight_smile:

Thanks for prompt responses, Taifun and br Alex

try this suggestion

Taifun

1 Like

I did and that seems to work regarding fine location but updates like in the 1990 :slight_smile:

speed:


Location on streets, as it should be but less then 10 udates in few km log test trip…

Will try now with 5s update time (the only thing I did not done from above) to see what happens and report in like 15 …20 minutes :slight_smile: :sunglasses:

BR Alex

5s was totaly uselec… got 3 updates in like 5 minutes… I then took off fine location for app in settings. In app I have lthat:
blocks

and when app starts I only gave this time permission. And that gives me the following result:
speed:


location:
image

as you can see, location was was updating like every 3…5s in one direction but then it stops on the way back. I can’t see any reason for that as you can see app logs constantly without any problems… But it is interesting that previuse drive actualy produced same patern… At the begining it does update but then stops… :sob:

If you have any more suggestion I will try tomorrow :slight_smile:

br Alex

how do you keep your app up and running while doing this drive?
as you probably know, I developed a locationservice extension, which is able to run in the background while your app is closed…

also the extension offers 2 methods to ask for the location permissions,

  1. RequestLocationPermission, which requests the basic location permissions (coarse and fine)
  2. RequestLocationBackgroundPermmission

Note : Starting with Android 12 asking the user to grant location permission got again more complicated, see also this stackoverflow answer. The extension therefore offers 2 methods to ask for the required permissions.

Taifun

App is always on main screen. I had idea to redo it with background tasks but I am a little to lazy for doing that :slight_smile: I am familliar with your extension. As I said I bought a few from you already in the past :cowboy_hat_face:

You think that extension could be the solution?

Br Alex

btw Taifun, thats how it looks when all working :wink:

https://grafana.optimpro.si/dashboard/snapshot/d9YfKQryWxSrkPY7hE2U7xWJwVfdYBne?orgId=2

This does not answer the question…

Usually the device gioes to sleep if you do not use it… so usually the location sensor does not work anymore afrer a while if you do not use a nethod to keep the screen on… however doing this obviously drains the battery faster…

Yrs, to use the location sensor in the background and store the data in TinyDB

Taifun

App do much more then just collect data from GPS. It does connect to a car via BT OBD and it constantly polls data from the engine. Then it does the neccesery calculations to extract everything and sends that to remote database with an api call to backend server. Also it shows some data on screen in real time and provide deep register anlaitics (down to bit ) so I can discover other data that I know are present in those registers.

So it never goes to sleep as it always show something on screen (usualy speed, RPM, temperature, saturation and back preassure of the FAP filter, its regeneration status, kilometers from the last regeneration and some other stuff I like to see :slight_smile: )

Very basic visualisation to keep data refresh speed as hi as possible. Because of really a lot of data (from 22.1.2021 till today there is 7.312.774 records in the database, 22 minutes today gave almost 13.000 new records - around 10 per second of driving) I use dictionary for temp storage to avoid constant writing to SD card. Thats why I changed from sqlite to dictionary and also gained some speed that way.

So I don’t think it is a background issue but I am willing to try if you provide me an extension to try. If it solve the issue I am sure ready to pay you asked price.

br Alex

which means, generally my extension can not help for your main purposes… see again the description what it is able to do…

always showing something on the screen does not prevent the app from going to sleep… at least you will have to set the KeepScreenOn property to true for that

Taifun

yes and I did and it does run forever and with android <12 everything worked like a charm… now GPS really suks…I tried what ever fall to my mind and nothig helped… I put both permissions request in app itself (coarse and fine location) and nothign … Need to see how to make extension that would follow requests for permisions…

exactly. I need to rewrite whole code if I want to use background services. but at the moment I do not really know how all togehter work as I never look into it :slight_smile:

br Alex

If I were you I would use your current logic while the app is up an running… and concerning the permission issue you have the following choices

  1. wait a few weeks or months, until Kodular added the functionality
  2. ask an extension developer to write the extension for you for free
  3. write the extension yourself and provide it for free to the community
  4. buy the location sensor extension and use only the method

Taifun

As you suggested, my intention was to leave it as is and learn how to make that short extension for permissions but… From I do not know the reason today on the way to office, it worked as it should. I will see what will be on next drive…
speed:

location:

but for sure I’ll learn extensions as it seems that is good to know. And I’ll report how it will work later today, tomorrow…

Thanks for replys and suggestions Taifun.

Best regards, Alex.