'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
' the Geocoder object can be declared as Process_Global - it is NOT an Activity object.
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.
Dim LatitudeEdit As EditText
Dim LongitudeEdit As EditText
Dim ResultsList As ListView
Dim AddressEdit As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Geocoder1.Initialize
End If
Activity.LoadLayout("GetFromLocation")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
ResultsList.Clear
Dim Latitude, Longitude As Double
Latitude=LatitudeEdit.Text
Longitude=LongitudeEdit.Text
' MaxResults parameter hardcoded to 5 for the demo
Dim MaxResults As Int
MaxResults=5
Dim Results() As Address
Results=Geocoder1.GetFromLocation(Latitude, Longitude, MaxResults)
If Results.Length>0 Then
Dim Address1 As Address
Dim i As Int
For i=0 To Results.Length-1
Address1=Results(i)
' check the reference to see all possible properties of the Address object
' http://www.b4x.com/forum/additional-libraries-classes-official-updates/17115-geocoder-library.html#post97857
' the CountryName property is what you're asking for:
' Returns the localized country name of the Address.
' For example "Iceland", OR Null if it Is unknown.
ResultsList.AddSingleLine(Address1.CountryName)
' ResultsList.AddTwoLines(Address1.PostalCode, Address1.CountryName)
Next
Else
Msgbox("GetFromLocation", "No Address matched the Latitude and Longitude")
End If
End Sub