#Region Project Attributes
#ApplicationLabel: GpsGsm Test
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#BridgeLogger: True
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
Dim Fused As FusedLocationProviderClient
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
Dim A1 As LocationF
Private LabelDistancia As Label
Private LabelLat As Label
Private LabelLon As Label
Private LabelBearing As Label
Private LabelBearingTo As Label
Private LabelBearingAccuracyDegrees As Label
Private LabelProvider As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim rp As RuntimePermissions
rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
Activity.LoadLayout("Layout")
End Sub
Sub Activity_Resume
A1.Initialize
A1.Latitude = 4.703274
A1.Longitude = -74.130271
DefineFused
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub DefineFused
Fused.Initialize("Fused")
Fused.GetLocationAvailability 'Determine if Location services are available
Wait For Fused_LocationAvailabilityRequestCompleted (Available As Boolean)
If Available Then
Fused.GetLastLocation
Wait For Fused_LocationRequestCompleted (Result As LocationResult)
If Result.Status=LocationResult.STATUS_SUCCESSFUL Then
Dim Loc As LocationF = Result.Location
Log(Loc.Latitude)
'Do other things with result...
Else
Log(Result.ErrorMessage)
End If
Dim LocationRequest1 As LocationRequest
LocationRequest1.Initialize(1000) 'Refresh interval is 1000 miliseconds
LocationRequest1.SetMinUpdateIntervalMillis(100) 'Minimum refresh interval is 100 miliseconds
LocationRequest1.SetPriority(Priority.PRIORITY_HIGH_ACCURACY) 'Request high accuracy location
LocationRequest1.SetMinUpdateDistanceMeters(0) 'Minimum distance on wich will fire location change event
LocationRequest1.SetGranularity(Granularity.GRANULARITY_FINE)
Fused.RequestLocationUpdates(LocationRequest1) 'Set location request to FusedLocationProviderClient
End If
End Sub
Sub Fused_LocationChanged(mLocation As LocationF)
'LocationF is equivalent for Location in GPS library but with more methods and properties'
LabelDistancia.Text = NumFormat6(mLocation.DistanceTo(A1), 0)
LabelLat.Text = NumFormat6(mLocation.Latitude, 6)
LabelLon.Text = NumFormat6(mLocation.Longitude, 6)
LabelBearing.Text = mLocation.Bearing
LabelBearingAccuracyDegrees.Text = mLocation.BearingAccuracyDegrees
LabelBearingTo.Text = NumFormat6(mLocation.BearingTo(A1), 2)
LabelProvider.Text = mLocation.Provider
End Sub
Sub NumFormat6(Num As Double, Decimales As Int) As String
Return(NumberFormat2(Num, 1, Decimales, Decimales, False))
End Sub