Get Current Location (Android)

Call this method to get the current location of the user at your desired accuracy level.

Current Location

Get the current location of the user. You can set the accuracy between 5 and 100 meters (default is 10). This method has two outputs.

  1. Callback Method which returns the current location with a faster response time. However, the accuracy depends on the current GPS connectivity.

  2. Location Receiver which returns the next two location updates which will have higher accuracy compared to the callback and takes time from a few hundred milliseconds to a couple of seconds based on the GPS and network connectivity.

Roam.getCurrentLocation(accuracy)

To listen to location updates, create a class that extends RoamReceiver. Then register the receiver by adding a receiver element to the application element in your manifest.

<application>
        ...
     <receiver android:name=".LocationReceiver"
                    android:enabled="true"
                    android:exported="false">
         <intent-filter>
         <action android:name="com.roam.android.RECEIVED"/>
         </intent-filter>
     </receiver>
         ...
</application>

Add the code to the receiver.

class LocationReceiver : RoamReceiver() {
      override fun onLocationUpdated(context: Context?, roamLocation: RoamLocation?) {
            // receive own location updates here
            // do something with location data using location
      }
}

To get the current location of the user in the callback, use the following code:

Roam.getCurrentLocation(DesiredAccuracy, accuracy, object : RoamLocationCallback {
            override fun location(location: Location?) {
                // Access location data here
            }
            override fun onFailure(roamError: RoamError) {
                // Access Error code and message here
                // roamError.code
                // roamError.message
            }
})

Parameter

Description

DesiredAccuracy

RoamTrackingMode.DesiredAccuracy.HIGH RoamTrackingMode.DesiredAccuracy.MEDIUM RoamTrackingMode.DesiredAccuracy.LOW

Last updated