Android Question GPS Location without moving (Get current location)

Halil Çağrı AKKUZU

New Member
Licensed User
Hi guys.
I have to get lat and lon values for my project but i only use it one time on opening.
LocationChange event trigger when device is moving. I want to get location without moving and without locationchange event, how can i do it ? Get current location.

Now im using, this kind of codes.

B4X:
Sub Activity_Resume
    If GPS1.GPSEnabled = False Then
        ToastMessageShow("You have to open location service.", True)
        StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
    Else
        rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        If Result Then CallSubDelayed(Me,"StartGPS")
    End If
End Sub

Public Sub StartGps
    GPS1.Start(0, 0)
    ProgressDialogShow("Getting GPS Values")
End Sub

Sub GPS_LocationChanged (Location1 As Location)
    Log("LATI:" & Location1.Latitude)
    Log("LONG:" & Location1.Longitude)
    StopGps
End Sub
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
1. Please use [CODE]code here...[/CODE] tags when posting code.

codetag001.png

codetag002.png

codetag003.png


LocationChange event trigger when device is moving
No. It raises when there is a known Location found using the Satelites. You do not need to move. Just give the GPS some time to get a fixed Location. Make sure to test it outside. Indoors the GPS Signal is weak
 
Upvote 0

Halil Çağrı AKKUZU

New Member
Licensed User
1. Please use [CODE]code here...[/CODE] tags when posting code.

codetag001.png

codetag002.png

codetag003.png



No. It raises when there is a known Location found using the Satelites. You do not need to move. Just give the GPS some time to get a fixed Location. Make sure to test it outside. Indoors the GPS Signal is weak

Sorry for that i did not know the CODE tag.

But i know some apps (example. google maps) is get better gps location (less time without moving and indoor)
Sometimes this time is take soo long (like 1 min.) And this is broke my app work flow.

So there is no another library or code example in b4a then this code ? (LocationChange event)
If not , have to use this code and think another solution. Thanks anyway.
 
Upvote 0
Top