'Activity module
Sub Process_Globals
Dim LocationInputMode As String
Dim MapCenter As GeoPoint
Dim ZoomLevel As Int
End Sub
Sub Globals
Dim AutoButton, GoButton, ManualButton As Button
Dim MapView1 As MapView
Dim MyLocationOverlay1 As MyLocationOverlay
Dim SimpleLocationOverlay1 As SimpleLocationOverlay
End Sub
Sub Activity_Create(FirstTime As Boolean)
ManualButton.Initialize("AButton")
ManualButton.Text="Manual"
Activity.AddView(ManualButton, 0, 0, 33%x, 48dip)
AutoButton.Initialize("AButton")
AutoButton.Text="Auto"
Activity.AddView(AutoButton, 33%x, 0, 33%x, 48dip)
GoButton.Initialize("AButton")
GoButton.Enabled=False
GoButton.Text="Go"
Activity.AddView(GoButton, 66%x, 0, 33%x, 48dip)
MapView1.Initialize("MapView1")
Activity.AddView(MapView1, 0, 48dip, 100%x, 100%y-48dip)
MapView1.SetZoomEnabled(True)
MapView1.SetMultiTouchEnabled(True)
MyLocationOverlay1.Initialize(MapView1, "MyLocationOverlay1")
SimpleLocationOverlay1.Initialize(MapView1)
If FirstTime Then
LocationInputMode=""
' use the new BoundingBox Initialize2 method to create a bounds of the UK
Dim UKBounds As BoundingBox
Dim NorthWest, SouthEast As GeoPoint
NorthWest.Initialize(58.77, -13.8)
SouthEast.Initialize(50.49, 3.4)
UKBounds.Initialize2(NorthWest, SouthEast)
' i could have instead used the Initialize method:
' UKBounds.Initialize(58.77, -13.8, 50.49, 3.4)
MapView1.FitMapToBoundingBox(UKBounds)
Else
MapView1.Zoom=ZoomLevel
MapView1.SetCenter3(MapCenter)
End If
If LocationInputMode<>"" Then
SetLocationInputMode(LocationInputMode)
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
MapCenter=MapView1.GetCenter
ZoomLevel=MapView1.Zoom
' disable GPS tracking
MyLocationOverlay1.MyLocationEnabled=False
End Sub
Sub AButton_Click
Dim ClickedButton As Button
ClickedButton=Sender
If ClickedButton.Text="Go" Then
MapCenter=MapView1.GetCenter
StartActivity(HandleLocation)
Else
SetLocationInputMode(ClickedButton.Text)
End If
End Sub
Sub MapView1_CenterChanged
If LocationInputMode="Manual" Then
SimpleLocationOverlay1.SetMyLocation3(MapView1.GetCenter)
End If
End Sub
Sub MyLocationOverlay1_FollowLocationAutoDisabled
AutoButton.Enabled=True
ToastMessageShow("Click Auto to follow your GPS location", False)
End Sub
Sub MyLocationOverlay1_LocationChanged(NewLocation As Location, IsFirstFix As Boolean)
If MyLocationOverlay1.FollowLocationEnabled Then
Dim OptimalZoomLevel As Int
OptimalZoomLevel=MapView1.GetMaxZoomLevel-2
If MapView1.Zoom<OptimalZoomLevel Then
MapView1.Zoom=OptimalZoomLevel
ToastMessageShow("Zooming to your GPS location", False)
End If
End If
End Sub
Sub SetLocationInputMode(Mode As String)
Select Mode
Case "Manual"
MapView1.RemoveOverlay(MyLocationOverlay1)
MyLocationOverlay1.MyLocationEnabled=False
AutoButton.Enabled=True
MapView1.AddOverlay(SimpleLocationOverlay1)
SimpleLocationOverlay1.SetMyLocation3(MapView1.GetCenter)
ManualButton.Enabled=False
ToastMessageShow("Pan & zoom the map to a location", False)
LocationInputMode="Manual"
Case "Auto"
MapView1.RemoveOverlay(SimpleLocationOverlay1)
ManualButton.Enabled=True
MyLocationOverlay1.MyLocationEnabled=True
MyLocationOverlay1.FollowLocationEnabled=True
MapView1.AddOverlay(MyLocationOverlay1)
AutoButton.Enabled=False
ToastMessageShow("Following your GPS location", False)
LocationInputMode="Auto"
End Select
If GoButton.Enabled=False Then
GoButton.Enabled=True
End If
End Sub