Getting started with GPS

jschuchert

Active Member
Licensed User
Longtime User
I copied and pasted the code from the tutorial into a separate module activity in my app. My application contains a menu of buttons, each starting an activity when clicked. However, the button assigned to start the gps activity does nothing. It seems like the only difference is that the example in the tutorial uses 'Main' as the activity module whereas mine is only one of many. I made a new layout for the activity but it does not display when the button mentioned is selected. The GPS library is there. Any ideas?

Jim S.
 

jschuchert

Active Member
Licensed User
Longtime User
Thank you for your willingness to assist. The project is quite large so I will only show the pertinent code relative to what I am referring. Everything in my application works well when the applicable menu button is chosen EXCEPT the gps routine. I can't even get the layout to display. I have checked spelling, etc. The gps tutorial executes fine but not MY code as a separate routine as follows:

Below is essentially the same as the tutorial

B4X:
Sub Process_Globals
   Dim GPS1 As GPS
End Sub

Sub Globals
   Dim lblLon As Label
   Dim lblLat As Label
   Dim lblSpeed As Label
   Dim lblSatellites As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      GPS1.Initialize("GPS")
   End If
   Activity.LoadLayout("gpsposition")  '<<<<<<<NAME OF THE LAYOUT
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

Sub GPS_GpsStatus (Satellites As List)
   lblSatellites.Text = "Satellites:" & CRLF
   For i = 0 To Satellites.Size - 1
      Dim Satellite As GPSSatellite
      Satellite = Satellites.Get(i)
      lblSatellites.Text = lblSatellites.Text & CRLF & Satellite.Prn & _
         " " & Satellite.Snr & " " & Satellite.UsedInFix & " " & Satellite.Azimuth _ 
         & " " & Satellite.Elevation
   Next
End Sub

below is a portion of the 'Sub Globals' for the 'menu' activity in my application

B4X:
Sub Globals
.
.
.
Dim btnResection As Button 
Dim btn3ptscurve As Button 
Dim btnculdesac As Button 
Dim btnplot As Button 
Dim btnStart As Button 
Dim btngps As Button '<<<<<<<THIS BUTTON STARTS THE ACTIVITY
End Sub

partial list of activities

B4X:
.
.
.
Sub btnMapChk_click
StartActivity(lotclose)
End Sub
Sub btnculdesac_click
StartActivity(culdesac)
End Sub

Sub btngps_click  
StartActivity(gpss)  '<<<<<<<< NAME OF THE ACTIVITY= 'GPSS'
End Sub

Below is an image of part of the application's menu with the gps button at the lower right

gpsmenubutton.jpg


Hopefully you or someone else can see what I have done to cause the problem or need additional information. I will continue with my own troubleshooting and post back if I identify the issue. Thanks to all.

Jim S.
 
Upvote 0

jschuchert

Active Member
Licensed User
Longtime User
Klaus, thank you for looking at it. I found the problem. I had failed to update the name of the button "button1" to btngps. It works now, including finding the satellites. You probably haven't heard the last of me, though, as I delve a little deeper to make it more useful.

Incidentally, is there a way to include tags within tags for forum messages.
Seems like I used to do it. For example...within the code tag...make some lines a different color. When I tried that, it converted it to html without changing the color. Probably something I have forgotten or never learned.

Jim S.
 
Upvote 0
Top