Android Question How to check for current altitude?

trueboss323

Active Member
Licensed User
Longtime User
I am using Fused Geocode location in my app, but I am not sure what area in the code is the right spot to get an accurate result.

B4X:
Sub Globals
    Dim lc As Geocoder
End Sub
Sub Process_Globals
  Private FusedLocationProvider1 As FusedLocationProvider
End Sub

Sub Activity_Create(FirstTime As Boolean)
   FusedLocationProvider1.Initialize("FusedLocationProvider1")
End Sub


Sub FusedLocationProvider1_ConnectionSuccess
    Log("FusedLocationProvider1_ConnectionSuccess")

    Dim LastKnownLocation As Location
    LastKnownLocation = FusedLocationProvider1.GetLastKnownLocation
    Log(LastKnownLocation.Altitude)
    If LastKnownLocation.IsInitialized Then
        GeocodeLocation(LastKnownLocation)
    Else
        Dim LocationRequest1 As LocationRequest
        LocationRequest1.Initialize
        LocationRequest1.SetInterval(1000)    '    1000 milliseconds
        LocationRequest1.SetPriority(LocationRequest1.Priority.PRIORITY_NO_POWER)
        LocationRequest1.SetSmallestDisplacement(1)    '    1 meter
       FusedLocationProvider1.RequestLocationUpdates(LocationRequest1)

    End If
End Sub

Sub FusedLocationProvider1_LocationChanged(Location1 As Location)
    Log("FusedLocationProvider1_LocationChanged")

    FusedLocationProvider1.RemoveLocationUpdates
    GeocodeLocation(Location1)
End Sub

Sub GeocodeLocation(Location1 As Location)
    Log("GeocodeLocation: "&Location1.Latitude&", "&Location1.Longitude)
    '    here you can get the Location Latitude and Longitude properties and use the Geocoder library to perform a reverse geocode
    '    if the reverse geocode is successful you will have the country that the device is located in

'lc.GetFromLocation(Location1.Latitude, Location1.Longitude,1,Null)
Longitude = Location1.Longitude
Latitude = Location1.Latitude

lc.Initialize2("lc","en")
Log(lc)
End Sub[

Sub lc_GeocodeDone(Results() As Address, Tag As Object)
   Try
   ' If Results.Length>0 Then
      
        Dim i As Int
        Dim Address1 As Address
        Dim loc As Location
            Address1=Results(i)
 
         'Checks the location
                Log("Country Code: "&Address1.CountryCode)
            If Address1.CountryCode = "US" Then
            Log("You are in the United States")          
            End If
End Sub

Sub button_click
   lc.GetFromLocation(Latitude, Longitude, MaxResults, Null)
End Sub

So the idea is every time a user presses a button, it should get their current altitude. But I don't know where or how to put the code.
 
Last edited:
Top