Android Tutorial GPS / GNSS tutorial

Status
Not open for further replies.
The GNSS library replaces the old GPS library. The GNSS library is available here: https://www.b4x.com/android/forum/threads/gnss-library-an-updated-gps-library.109110/#content


1741875843450.png


Using it is quite simple:
1. Checking whether location services are available. If not take the user to the settings.
2. Request permission.

If the purpose is to get the user location then the FusedLocationProvider might be a better option: https://www.b4x.com/android/forum/threads/fusedlocationprovider-resolution-dialog.111652/#content
 

Attachments

Last edited:
Result of bearingto is negativ

Hello!

I have calculate the bearing from my own position to the target-position with

B4X:
Expand Collapse Copy
Kurs=GPS1.BearingTo(Target)

The result of Kurs is negativ and not equal with the real bearing. :confused::confused:
 
Hello Erel!

Is it possible, that the bearing is not shown in 0-360°? When it is shown from 0-180 and -180 to 0°, I think it is correct...:sign0013:
 
So, isn't possible programmatical on\off (connect\disconnect) of Android's GPS subsystem (like in WM 5.x-6.x)? Without manual user's choice.
I mean periodical GPS auto-connect by a software only.
 
So, isn't possible programmatical on\off (connect\disconnect) of Android's GPS subsystem (like in WM 5.x-6.x)? Without manual user's choice.
No, it's not possible. As Erel stated above.
Due to privacy concerns the Android OS doesn't allow you to turn the GPS on programatically.
 
Ha, so this is enough. Just an extra manual permission from a user, i see.
Thanks, Erel.
Now just interesting about background running application and switching the screen off, again for battery economy.
 
Last edited:
Hi,

Good work ;) but what about the NMEA ? ( hxxp://developer.android.com/reference/android/location/GpsStatus.NmeaListener.html )
How to get those frames? :confused:

Thx
 
Last edited:
Why when I try this code no message shows up when pressing the home button?

B4X:
Expand Collapse Copy
Sub Activity_Pause (UserClosed As Boolean)

   Dim Results4 As Int
   Results4 = Msgbox2("Just a msg", "Try","OK", "", "", LoadBitmap (File.DirAssets,"Signal.png"))
   If Results4 = DialogResponse.POSITIVE Then
   End If
   
   GPS1.Stop
   Awake.ReleaseKeepAlive

End Sub

Thanks
 
Thanks Erel, I have noticed one other thing that dose not make since to me:
I have created a small GPS app following your example above; (just to understand the process correctly). What I have tried to do is to make the app shows all the information to the user (Lat, Lng. …) and do some other tasks in the background (track the user movement).
What I have noticed that while the app is running everything works fine until the user gets a phone call which forces my app to pause, and force the GPS to turn off, therefore I changed the code as shown below:

B4X:
Expand Collapse Copy
Sub Activity_Pause (UserClosed As Boolean)

End Sub

Note: I have added an if statement to the “Activity_Resume” sub to insure that I’m not calling GPS1.Start while the GPS is already on)

Now when the app being pushed to the background because of a phone call (or maybe the user decided to play music or surf the Internet) the GPS will stay on, but the application somehow will be paused (the tracking function is not recording anything while the application is in the background)

Is this issue due to Android hardware limitation? If yes then how come you can play music and surf the Internet at the same time?

Thank you all
 
Last edited:
Erel,

If I understand this correctly, this is a Basic4Android limitation, it is not Android operating system limitation, is that right?

And when you say in the future dose that means the next Basic4Android version?

Regards
:sign0148:
 
If I understand this correctly, this is a Basic4Android limitation, it is not Android operating system limitation, is that right?
No, that is not correct. This is Android OS limitation (or actually design).

And when you say in the future dose that means the next Basic4Android version?
It is planned for the next major update.
 
Status
Not open for further replies.
Top