Region Project Attributes
#ApplicationLabel: FusedLocationProvider example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
'#AdditionalRes: C:\Android\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms
#additionaljar: com.android.support:support-v4
#AdditionalJar: com.google.android.gms:play-services-location
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Private FusedLocationProvider1 As FusedLocationProvider
Private LastLocation As Location
End Sub
Sub Globals
Private LastLocationLabel As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
' ** IMPORTANT see manifest for required entries **
If FirstTime Then
FusedLocationProvider1.Initialize("FusedLocationProvider1")
End If
Activity.LoadLayout("Main")
If LastLocation.IsInitialized Then
UpdateUI
End If
End Sub
Sub Activity_Resume
' attempt to connect to the location services
' after calling Connect we are waiting for either ConnectionFailed or ConnectionSuccess events
FusedLocationProvider1.Connect
End Sub
Sub Activity_Pause (UserClosed As Boolean)
FusedLocationProvider1.Disconnect
End Sub
Sub FusedLocationProvider1_ConnectionFailed(ConnectionResult1 As Int)
Log("FusedLocationProvider1_ConnectionFailed")
' the FusedLocationProvider ConnectionResult object contains the various CoonectionResult constants
Select ConnectionResult1
Case FusedLocationProvider1.ConnectionResult.NETWORK_ERROR
' a network error has occurred, this is likely to be a recoverable error
' so try to connect again
FusedLocationProvider1.Connect
Case Else
' TODO handle other errors
End Select
End Sub
Sub FusedLocationProvider1_ConnectionSuccess
Log("FusedLocationProvider1_ConnectionSuccess")
Dim LocationRequest1 As LocationRequest
LocationRequest1.Initialize
LocationRequest1.SetInterval(1000) ' 1000 milliseconds
LocationRequest1.SetPriority(LocationRequest1.Priority.PRIORITY_HIGH_ACCURACY)
LocationRequest1.SetSmallestDisplacement(1) ' 1 meter
FusedLocationProvider1.RequestLocationUpdates(LocationRequest1)
End Sub
Sub FusedLocationProvider1_ConnectionSuspended(SuspendedCause1 As Int)
Log("FusedLocationProvider1_ConnectionSuspended")
' the FusedLocationProvider SuspendedCause object contains the various SuspendedCause constants
Select SuspendedCause1
Case FusedLocationProvider1.SuspendedCause.CAUSE_NETWORK_LOST
' TODO take action
Case FusedLocationProvider1.SuspendedCause.CAUSE_SERVICE_DISCONNECTED
' TODO take action
End Select
End Sub
Sub FusedLocationProvider1_LocationChanged(Location1 As Location)
Log("FusedLocationProvider1_LocationChanged")
LastLocation=Location1
UpdateUI
End Sub
Sub UpdateUI
LastLocationLabel.Text=DateTime.Time(LastLocation.Time)&" ("&LastLocation.Latitude&", "&LastLocation.Longitude&")"
End Sub