'Code module
#Region Project Attributes
#ApplicationLabel: B4i Example
#Version: 1.0.0
'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
#iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
#iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#PlistExtra:<key>NSLocationWhenInUseUsageDescription</key><string>Used to display the current navigation data.</string>
#PlistExtra:<key>NSLocationUsageDescription</key><string>Used to display the current navigation data.</string>
#End Region
#IgnoreWarnings: 17
'use the distribution certificate
#CertificateFile: ios_distribution.cer
'#Entitlement: <key>aps-environment</key><string>production</string>
#ProvisionFile: Adhoc.mobileprovision
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public App As Application
Public NavControl As NavigationController
Private Page1 As Page
Private LocManager As LocationManager
Private lblAccuracy As Label
Private lblAltitude As Label
Private lblBearing As Label
Private lblEnable As Label
Private lblHeading As Label
Private lblLL As Label
Private lblSpeed As Label
Private lblTime As Label
Public gpsTime As Long
Private GPSTimer As Timer
End Sub
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
Page1.RootPanel.Color = Colors.White
Page1.RootPanel.LoadLayout("2")
NavControl.ShowPage(Page1)
LocManager.Initialize("LocManager")
GPSTimer.Initialize("GPSTimer",1000)
GPSTimer.Enabled = True
End Sub
Private Sub LocManager_AuthorizationStatusChanged (Status As Int)
lblEnable.Visible = (LocManager.AuthorizationStatus = LocManager.AUTHORIZATION_DENIED _
Or LocManager.AuthorizationStatus = LocManager.AUTHORIZATION_RESTRICTED)
StartLocationUpdates
End Sub
Private Sub StartLocationUpdates
'if the user allowed us to use the location service or if we never asked the user before then we call LocationManager.Start.
If LocManager.IsAuthorized Or LocManager.AuthorizationStatus = LocManager.AUTHORIZATION_NOT_DETERMINED Then
LocManager.Start(0)
End If
LocManager.StartHeading
End Sub
Private Sub Application_Foreground
StartLocationUpdates
End Sub
Private Sub Application_Background
LocManager.Stop
LocManager.StopHeading
End Sub
Private Sub LocManager_HeadingChanged (MagneticHeading As Double, TrueHeading As Double)
If TrueHeading >= 0 Then
lblHeading.Text = NumberFormat(TrueHeading, 1, 0) & Chr(176) & " (true north)"
Else
lblHeading.Text = NumberFormat(MagneticHeading, 1, 0) & Chr(176) & " (magnetic)"
End If
End Sub
Sub LocManager_AllowCalibration As Boolean
Return
End Sub
Private Sub LocManager_LocationError
Log("Error: " & LastException.Description)
End Sub
Private Sub LocManager_LocationChanged (Location1 As Location)
If Location1.VerticalAccuracy >= 0 Then
lblAltitude.Text = NumberFormat(Location1.Altitude, 1, 1) & "m"
Else
lblAltitude.Text = "N/A"
End If
lblBearing.Text = ValueOrNA (Location1.Bearing, 1, Chr(176))
If Location1.Accuracy >= 0 Then
lblLL.Text = NumberFormat(Location1.Latitude, 2, 4) & " / " & NumberFormat(Location1.Longitude, 2, 4)
Else
lblLL.Text = "N/A"
End If
lblSpeed.Text = ValueOrNA(Location1.Speed, 1, "m/s")
If Location1.Time > 0 Then
gpsTime = DateTime.Now - Location1.Time
End If
lblAccuracy.Text = ValueOrNA(Location1.Accuracy, 2, "m")
End Sub
Private Sub ValueOrNA(value As Double, NumberOfFractions As Int, unit As String) As String
If value < 0 Then
Return "N/A"
Else
Return NumberFormat(value, 1, NumberOfFractions) & unit
End If
End Sub
Sub GpsTimer_Tick
Dim Time As Long
Time = DateTime.Now - gpsTime
lblTime.Text = DateTime.Time(Time)
End Sub