Hi, i want to keep my location (longitude and latitude) from wifi (not gps), i used the example from this link
https://www.b4x.com/android/forum/threads/fusedlocationprovider.50614/
but i don't display nothing, don't retrive the longitude and latitude.
this is my code:
and this is the manifest
https://www.b4x.com/android/forum/threads/fusedlocationprovider.50614/
but i don't display nothing, don't retrive the longitude and latitude.
this is my code:
B4X:
#Region Project Attributes
#ApplicationLabel: FusedLocationProvider example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#AdditionalJar: com.android.support:support-v4
#AdditionalJar: com.google.android.gms:play-services-location
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Private FusedLocationProvider1 As FusedLocationProvider
Private LastLocation As Location
End Sub
Sub Globals
Private LastLocationLabel As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
' ** IMPORTANT see manifest for required entries **
If FirstTime Then
FusedLocationProvider1.Initialize("FusedLocationProvider1")
End If
Activity.LoadLayout("Main")
If LastLocation.IsInitialized Then
UpdateUI
End If
End Sub
Sub Activity_Resume
' attempt to connect to the location services
' after calling Connect we are waiting for either ConnectionFailed or ConnectionSuccess events
FusedLocationProvider1.Connect
End Sub
Sub Activity_Pause (UserClosed As Boolean)
FusedLocationProvider1.Disconnect
End Sub
Sub FusedLocationProvider1_ConnectionFailed(ConnectionResult1 As Int)
Log("FusedLocationProvider1_ConnectionFailed")
' the FusedLocationProvider ConnectionResult object contains the various CoonectionResult constants
Select ConnectionResult1
Case FusedLocationProvider1.ConnectionResult.NETWORK_ERROR
' a network error has occurred, this is likely to be a recoverable error
' so try to connect again
FusedLocationProvider1.Connect
Case Else
' TODO handle other errors
End Select
End Sub
Sub FusedLocationProvider1_ConnectionSuccess
Log("FusedLocationProvider1_ConnectionSuccess")
Dim LocationRequest1 As LocationRequest
LocationRequest1.Initialize
LocationRequest1.SetInterval(1000) ' 1000 milliseconds
LocationRequest1.SetPriority(LocationRequest1.Priority.PRIORITY_HIGH_ACCURACY)
LocationRequest1.SetSmallestDisplacement(1) ' 1 meter
FusedLocationProvider1.RequestLocationUpdates(LocationRequest1)
End Sub
Sub FusedLocationProvider1_ConnectionSuspended(SuspendedCause1 As Int)
Log("FusedLocationProvider1_ConnectionSuspended")
' the FusedLocationProvider SuspendedCause object contains the various SuspendedCause constants
Select SuspendedCause1
Case FusedLocationProvider1.SuspendedCause.CAUSE_NETWORK_LOST
' TODO take action
Case FusedLocationProvider1.SuspendedCause.CAUSE_SERVICE_DISCONNECTED
' TODO take action
End Select
End Sub
Sub FusedLocationProvider1_LocationChanged(Location1 As Location)
Log("FusedLocationProvider1_LocationChanged")
LastLocation=Location1
UpdateUI
End Sub
Sub UpdateUI
LastLocationLabel.Text=DateTime.Time(LastLocation.Time)&" ("&LastLocation.Latitude&", "&LastLocation.Longitude&")"
End Sub
and this is the manifest
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")
'End of default text.
' FusedLocationProvider:
' required manifest entry required for Google Play Services
AddApplicationText(<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />)
' you must add one of these two permissions
' the permission you add will define the accuracy of location updates
AddPermission(android.permission.ACCESS_FINE_LOCATION)
AddPermission(android.permission.ACCESS_COARSE_LOCATION)