Android Question How to run the GPS activity by click

clooney48

Active Member
Licensed User
Longtime User
Hi!

I am an absolute beginner with b4a but I thought it should be easy to run an existing GPS sample by clicking on my button (StartGPS) in my new app. The values Lon & Lat should be only saved into labels. But I didn´t succeed. How can I do that?

B4X:
Sub Process_Globals
    Dim GPS1 As GPS
End Sub
 
Sub Globals
    Dim lblLon As Label
    Dim lblLat As Label
    Dim lblSpeed As Label
End Sub
 
Sub StartGPS_Click
..................?
    If FirstTime Then
        GPS1.Initialize("GPS")
    End If
..................?
End Sub
 
 
Sub Activity_Resume
    If GPS1.GPSEnabled = False Then
        ToastMessageShow("Please enable the GPS device.", True)
        StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
    Else
        GPS1.Start(0, 0) 'Listen to GPS with no filters.
    End If
End Sub
 
Sub Activity_Pause (UserClosed As Boolean)
    GPS1.Stop
End Sub
 
Sub GPS_LocationChanged (Location1 As Location)
    lblLat.Text = "Lat = " & Location1.ConvertToMinutes(Location1.Latitude)
    lblLon.Text = "Lon = " & Location1.ConvertToMinutes(Location1.Longitude)
    lblSpeed.Text = "Speed = " & Location1.Speed
End Sub
 
Sub GPS_UserEnabled (Enabled As Boolean)
    ToastMessageShow("GPS device enabled = " & Enabled, True)
End Sub
 
End Sub
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…