B4A Library GNSS library - an updated GPS library

Alessandro71

Well-Known Member
Licensed User
Longtime User
Yes. If you read the first post you can get some constellation data from the GPS library. GNSS gives you a lot of extra individual satellite data in the additional GNSSStatus event otherwise it is identical to the GPS library.

So the GPS library, even if it's named "GPS" (probably for historic reason) can actually receive data from GLONASS, for example?
If I'm only interested plain Location information (i.e. Latitude, Longitude, Speed) there is no added benefit in using GNSS?
 

Alessandro71

Well-Known Member
Licensed User
Longtime User
In the first post I have posted a warning about the deprecation of GpsStatus whan targeting SDK 31 or later. The original GPS library will no longer work in this situation as GpsStatus is no longer available for use.
It's not clear to me if this warning applies only to GNSS library or also to the built-in standard GPS library.
 

agraham

Expert
Licensed User
Longtime User
The standard GPS library is now hobbled in apps targeting SDK 31 running on Android 11, 12 and later (maybe 10 but I can't test it) as noted in this thread here - which prompted me to add the comment in the first post
 

Alessandro71

Well-Known Member
Licensed User
Longtime User
The Location object of the GNSS library is detected as different by the runtime system, from the Location object of the GPS library.
I discovered this while replacing GPS with GNSS in a project that is using FusedLocationProvider for SDK 31 compliancy:

java.lang.Exception: Sub flp_locationchanged signature does not match expected signature.

My app has 2 different build configuration:
a "Lite" version which uses FusedLocationProvider for fast but coarse location tracking
a "Pro" version which uses GNSS for precise location tracking

for "Lite" version I need to select FusedLocationProvider+GPS libraries while for "Pro" version I must deselect GPS and select GNSS
failure to do select the correct lib (GPS or GNSS) will not produce any error at compile time, but just at run time.
Is there an easy way to make sure I'm selecting the right lib in the right build mode?
I'm thinking about a stub code that causes a compile error when the wrong lib is selected for the current build configuration, maybe using an object that exists only in the correct lib.
Rephrasing my though: is there any code that compiles fine with GPS lib but not with GNSS and viceversa?
I will do some tests in this direction...
 

agraham

Expert
Licensed User
Longtime User
You can tell if you have GNSS selected at compile time by Dimming an instance of GNSStatus which should tell you even before compiling that the GNSS library is not selected. Also if you can Dim a GPSSatellite instance you have either GPS or GNSS selected. Perhaps you can put some conditional code in relying on a Lite or Pro symbol to enable it.
 

Alessandro71

Well-Known Member
Licensed User
Longtime User

Thank you for your feedback: meanwhile I devised the same approach:
B4X:
    #if Lite
    'fast location
    'unselect GNSS libray when using FLP
    Public flp As FusedLocationProvider
    Public GPSScanner as GPS    'unused: just to make sure we have selected the correct library (GPS and not GNSS)
    #else if Pro
    'precise location
    Public GPSScanner As GNSS
    #end if
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…