Android Question GPS Running on background

stevenindon

Active Member
Licensed User
Hello all,

I have downloaded the example of GPS running in background here :

https://www.b4x.com/android/forum/threads/background-location-tracking.99873/#content

I have been testing it for the last 3 days and everything was running fine...but once you go into buildings for too long and the background service unable to detect your GPS position,
the Notification will start showing : 'Tracking location ...' (*which is normal)

The problem starts when you go out from the building again and continue your travel (even after hours), the notification still shows : 'Tracking location ...'

Seems like the GPS_LocationChanged (Location1 As Location) does not fires up. How can i fix this issue... ? Please help
 

BlueVision

Active Member
Licensed User
Longtime User
I can't tell you exactly what the problem is, but I've had similar experiences.
For me it is like this. If I go into a building or drive through a tunnel, I usually lose the "position fix", i.e. the GPS receiver cannot determine the location due to poor satellite reception. Completely normal. In principle, this is not a problem as long as it does not take too long.
I have an app that recognises which of my clients I am with when I enter a building and saves this information for my reporting. When I'm done at the customer's (possibly after 3-4 hours), leave the building again and drive to the next customer, it sometimes takes what feels like an eternity until a "Position Fix" is displayed again and my GPS receiver is "online" again. The problem gets even worse when I am already on the move with the car. That sometimes takes 15 minutes.

I don't know exactly what this has to do with. GPS satellites are not geostationary, i.e. they move around in the sky as seen from Earth. Some satellites that were visible during the last position fix may no longer be. If I remember correctly, there is also a so-called GPS almanac (orbital data of the satellites). This is also sent by the satellites and stored in the GPS receiver. Based on this almanac, the approximate positions of the satellites can then be estimated by the device when the device is switched on again, in order to get a "position fix" more quickly again, or in other words, the GPS receiver can already make a preselection as to which satellites it should search for because they should be "visible". Maybe it has to do with that, I don't know exactly how long this almanac is valid on the respective device. Assuming it is out of date, the GPS unit will listen until it receives signals from some satellite. Usually there are at least 3 or 4 within a short period of time and then you can determine the location. To be honest, I don't think that almanac data becomes obsolete so quickly. They should be valid for at least a few days.

It should not be the programme itself, or rather the corresponding subroutine or the corresponding service, because I assume that it works as long as the period from the last valid "position fix" to the next valid fix is not too long.

As I said, it gets even worse if you also move a little faster (by car). Then you also constantly change your current position and it can take a long time...
I don't think it has anything to do with the service. It just doesn't fire because there is nothing to fire, there is no position fix. Watch the GPS icon on the smartphone. On many devices it flashes when there is no position fix.

Just my personal experience, of course it also depends on the GPS receiver itself. I experience the behaviour described above from time to time on my old HTC M7, not the latest model as I said. More modern smartphones are perhaps a bit more intelligent. But that is also just a guess.

Hope this helps a little bit.
 
Upvote 0

stevenindon

Active Member
Licensed User
Thank you BlueVision for sharing your thought and experience. Any others who have other weird experience with GPS running in background?
I am in the mid of testing and updating the function to improve GPS running on background.

Will drive around for more test..
 
Upvote 0

stevenindon

Active Member
Licensed User
Hello all, for the GPS to continue running in the background, I added Request Background permission.(*See attached image)
Was just wondering if this is even necessary in order to prevent GPS from stop working
(*After a long while inside a building, GPS lost its coordinates and just showing 'Tracking location...'. AFTER i continue go out in open space and driving for almost 1/2 hour..still just 'Tracking location...'). Seems that the GPS stops working...until i re-run the app.
 

Attachments

  • Bgmission.jpg
    Bgmission.jpg
    32.9 KB · Views: 170
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Errr...how can i check which API level? My SDK version in manifest : <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="30"/>
or are you refering to this : jdk-11.0.1?
What Android API level do the mobile phones on which you run your app have?
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Upvote 0
Top