Sub Process_Globals
End Sub
Sub Globals
Dim FIRST_ANIMATE As Boolean
Dim FLP As FusedLocationProvider
Dim OLCL As OnLocationChangedListener
Dim CLS As CustomLocationSource
Dim GMap As GoogleMap
Dim GMapEx As GoogleMapsExtras
Dim MFragment As MapFragment
Dim MPanel As Panel
Dim PWS As PhoneWakeState
End Sub
Sub Activity_Create(FirstTime As Boolean)
FIRST_ANIMATE = True
MPanel.Initialize("")
Activity.AddView(MPanel, 0, 0, 100%x, 100%y)
If MFragment.IsGooglePlayServicesAvailable = False Then
ToastMessageShow("Google Play services not available.", True)
Else
MFragment.Initialize("MFragment", MPanel)
End If
End Sub
Sub Activity_Resume
If Not(FLP.IsInitialized) Then
FLP.Initialize("FLP")
End If
If Not(FLP.IsConnected) Then
FLP.Connect
End If
PWS.KeepAlive(True)
PWS.PartialLock
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If FLP.IsConnected Or FLP.IsConnecting Then
FLP.Disconnect
End If
PWS.ReleaseKeepAlive
PWS.ReleasePartialLock
End Sub
Sub MFragment_Ready
GMap = MFragment.GetMap
If GMap.IsInitialized Then
GMap.GetUiSettings.CompassEnabled = True
GMap.GetUiSettings.MyLocationButtonEnabled = True
GMap.GetUiSettings.ZoomControlsEnabled = True
GMapEx.SetBuildingsEnabled(GMap, True)
GMapEx.SetIndoorEnabled(GMap, True)
GMapEx.SetTrafficEnabled(GMap, True)
CLS.Initialize("CLS")
GMapEx.SetLocationSource(GMap, CLS)
GMap.MyLocationEnabled = True
Else
ToastMessageShow("Error initializing GoogleMap", False)
End If
End Sub
Sub CLS_Activate(OnLocChangedListener As OnLocationChangedListener)
OLCL = OnLocChangedListener
FLP.Connect
End Sub
Sub CLS_Deactivate
FLP.Disconnect
End Sub
Sub FLP_ConnectionFailed(ConResult As Int)
Select ConResult
Case FLP.ConnectionResult.NETWORK_ERROR
ToastMessageShow("NETWORK ERROR" & CRLF & "RETRYING ...", False)
FLP.Connect
Case Else
ToastMessageShow("CONNECTION FAILED", False)
End Select
End Sub
Sub FLP_ConnectionSuccess
Dim LR As LocationRequest
LR.Initialize
LR.SetInterval(1000) 'Milliseconds
LR.SetPriority(LR.Priority.PRIORITY_HIGH_ACCURACY)
LR.SetSmallestDisplacement(1) 'Meters
FLP.RequestLocationUpdates(LR)
End Sub
Sub FLP_ConnectionSuspended(SuspCause As Int)
Select SuspCause
Case FLP.SuspendedCause.CAUSE_NETWORK_LOST
ToastMessageShow("NETWORK LOST", False)
Case FLP.SuspendedCause.CAUSE_SERVICE_DISCONNECTED
ToastMessageShow("SERVICE DISCONNECTED", False)
End Select
End Sub
Sub FLP_LocationChanged(NewLocation As Location)
OLCL.OnLocationChanged(NewLocation)
Dim ZOOM As Int
If FIRST_ANIMATE Then
FIRST_ANIMATE = False
ZOOM = 15
Else
ZOOM = GMap.CameraPosition.Zoom
End If
Dim CP As CameraPosition
CP.Initialize2(NewLocation.Latitude, NewLocation.Longitude, ZOOM, NewLocation.Bearing, 0)
GMap.AnimateCamera(CP)
End Sub