Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim GPS1 As GPS
Dim Place As Location
Dim Geocoder1 As Geocoder
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private DESCInput As EditText
Private DES_CancelButton As Button
Private DES_KeepButton As Button
Private DES_LocationDescription As EditText
Dim ResultsList As ListView
Dim su As StringFunctions
Dim GeoLat, GeoLon As Double
Dim Lon As String
Dim Lat As String
Dim Speed As String
Dim OnceOff As Int = 1
Dim SL As Boolean = False
Private ShowLocation As ToggleButton
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("GeocodeDecipher")
Place.Initialize
ResultsList.Initialize("")
If FirstTime Then
GPS1.Initialize("GPS")
Geocoder1.Initialize("Geocoder1")
End If
DESCInput.SingleLine = False
DES_LocationDescription.SingleLine = False
End Sub
Sub Activity_Resume
If GPS1.GPSEnabled = False Then
ToastMessageShow("Please enable the GPS device.", True)
StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
Else
GPS1.Start(0, 0) 'Listen to GPS with no filters.
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
GPS1.Stop
End Sub
Sub GPS_LocationChanged (Location1 As Location)
' Lat = Place.ConvertToMinutes(Location1.Latitude)
' Lon = Place.ConvertToMinutes(Location1.Longitude)
Lat = (Location1.Latitude)
Lon = (Location1.Longitude)
GeoLat = Location1.Latitude
GeoLon = Location1.Longitude
' Log("Lat: "&Lat&" Lon: "&Lon)
Speed = Location1.Speed
Location
End Sub
Sub Location
Dim MapIntent As Intent
Dim myPosition As String
Dim MaxResults As Int = 5
' myPosition = "geo:0,0?q=" & "40.7142, -74.0064"
Log("Latitude: "&Lat)
Log("Longitude: "&Lon)
myPosition = "geo:"&GeoLat&","&GeoLon&"?q=" & Lat &","& Lon
MapIntent.Initialize(MapIntent.ACTION_VIEW, myPosition)
Geocoder1.GetFromLocation(GeoLat, GeoLon, MaxResults, Null)
End Sub
Sub Geocoder1_GeocodeDone(Results() As Address, Tag As Object)
Dim AddressList As String
If Results.Length > 0 Then
Dim Address1 As Address
Dim i As Int
For i=0 To Results.Length -1
Address1=Results(i)
Log("Address1.AddressLines.Size="&Address1.AddressLines.Size)
If Address1.AddressLines.Size>0 Then
ResultsList.AddTwoLines(Address1.AddressLines.Get(0), Address1.AddressLines.Get(0))
AddressList = Address1.AddressLines.Get(0)&CRLF&Address1.Locality&CRLF&Address1.PostalCode&CRLF&Address1.CountryName
' Log(Address1.SubLocality&" - "&Address1.Thoroughfare)
' Msgbox("Closest Known Address is:"&CRLF&AddressList,"DEBUG")
If OnceOff = 1 Then
DES_LocationDescription.Text = AddressList
DES_LocationDescription.Invalidate
GPS1.Stop
OnceOff = OnceOff + 1
End If
End If
Next
Else
Msgbox("GetFromLocation", "No Address matched the Latitude and Longitude")
End If
End Sub