Android Question GPS sometimes return 0

bixmatech

Member
Licensed User
Hi ....

I'm using GPS (1.2) and LocationManager (1.10) libraries , for getting my location , but sometimes return 0 instead of the current location.

is there anything wrong in my code ?


B4X:
' GPS
Sub GetLocation
    Location.Initialize("Location")
    GPS1.Initialize("GPS")
   
    If GPS1.GPSEnabled = False Then
        StartActivity(GPS1.LocationSettingsIntent)
    Else
        rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    End If
End Sub

Sub Activity_PermissionResult (Permission As String, Result As Boolean)
    If Permission = rp.PERMISSION_ACCESS_FINE_LOCATION Then
        If Result Then
            GPS1.Start(0, 0)
            Location.requestMobileLocation
        Else
            GPS1.Stop
        End If
    End If
End Sub

Sub Location_LocationChanged (Longitude As Double, Latitude As Double, Altitude As Double, Accuracy As Float, Bearing As Float, Provider As String, Speed As Float, Time As Long)
    verb_Latitude  = Latitude
    verb_Longitude = Longitude

    Location.stopMobileListening
    GPS1.Stop
End Sub


Thank you
 

bixmatech

Member
Licensed User
Don't use LocationManager. Use GPS library if you are only interested in the GPS location or use FusedLocationProvider for all providers.

Could you please tell me what I've to change in my codes to get the current Lat/Long , by using just GPS lib ?

and where can I find "FusedLocationProvider' anyway :)

Thanks...
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

bixmatech

Member
Licensed User
Thank you all ...

DonManfred :
I tried "GPS Tutorial" and downloaded the GPS.zip from this page:
https://www.b4x.com/android/forum/threads/gps-tutorial.6592/#content

But didn't give me my location. (fields empty) (image attached) , so I tried the FusedLocationProvider lib , But some times doesn't give me any values. (Like LocationManager lib).

I just need the location nothing more.

Test it on : Sony Z Ultra (5.0.2)

Thank you ....
 

Attachments

  • image.jpg
    image.jpg
    52.8 KB · Views: 291
Upvote 0
Top