This is a new FusedLocationProviderGMS library that is based on the latest version of Google Mobile Services (GMS). Unlike the old version of the FusedLocationProvider library, this version uses the FusedLocationProviderClient class in place of the deprecated FusedLocationProvider class. The FusedLocationProviderClient class is based on asynchronous methods, while the old version uses synchronized methods that are deprecated.
The principle of using the library is very similar to the older version, and the difference is that the result for each request to read the current location or the last known location is asynchronous and when the procedure is finished, the defined event will be fired. If you need a synchronized method, use the WaitFor command.
It is also necessary to add the following line to the manifest to be able to use GMS FusedLocation:
Example:
If this libraries makes your work easier and saves time in creating your application, please make a donation.
www.paypal.com
The principle of using the library is very similar to the older version, and the difference is that the result for each request to read the current location or the last known location is asynchronous and when the procedure is finished, the defined event will be fired. If you need a synchronized method, use the WaitFor command.
It is also necessary to add the following line to the manifest to be able to use GMS FusedLocation:
Add to Manifest:
AddApplicationText(<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />)
Example:
B4X:
Sub Process_Globals
Dim Fused As FusedLocationProviderClient
End Sub
Sub DefineFused
Fused.Initialize("Fused")
Fused.GetLocationAvailability 'Determine if Location services are available
Wait For Fused_LocationAvailabilityRequestCompleted (Available As Boolean)
If Available Then
Fused.GetLastLocation
Wait For Fused_LocationRequestCompleted (Result As LocationResult)
If Result.Status=LocationResult.STATUS_SUCCESSFUL Then
Dim Loc As LocationF = Result.Location
Log(Loc.Latitude)
'Do other things with result...
Else
Log(Result.ErrorMessage)
End If
Dim LocationRequest1 As LocationRequest
LocationRequest1.Initialize(1000) 'Refresh interval is 1000 miliseconds
LocationRequest1.SetMinUpdateIntervalMillis(100) 'Minimum refresh interval is 100 miliseconds
LocationRequest1.SetPriority(Priority.PRIORITY_HIGH_ACCURACY) 'Request high accuracy location
LocationRequest1.SetMinUpdateDistanceMeters(0) 'Minimum distance on wich will fire location change event
LocationRequest1.SetGranularity(Granularity.GRANULARITY_FINE)
Fused.RequestLocationUpdates(LocationRequest1) 'Set location request to FusedLocationProviderClient
End If
End Sub
Sub Fused_LocationChanged(mLocation As LocationF)
'LocationF is equivalent for Location in GPS library but with more methods and properties'
End Sub
If this libraries makes your work easier and saves time in creating your application, please make a donation.

Donate to Ivica Golubovic
Help support Ivica Golubovic by donating or sharing with your friends.

Attachments
Last edited: