Get Current Location

Current Location

Get the current location of the user. You can set the accuracy from 5 to 100 meters (default is 10). This method has two outputs.
  1. 1.
    Callback Method which returns the current location with faster response time and the accuracy depends on the current GPS connectivity.
  2. 2.
    Location Receiver which returns the next two location updates which will be higher accuracy compared to the callback and takes time from few hundred milliseconds to a couple of seconds based on the GPS and network connectivity.
Kotlin
Java
1
Roam.getCurrentLocation(accuracy)
Copied!
1
Roam.getCurrentLocation(accuracy);
Copied!
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.
1
<application>
2
...
3
<receiver android:name=".LocationReceiver"
4
android:enabled="true"
5
android:exported="false">
6
<intent-filter>
7
<action android:name="com.roam.android.RECEIVED"/>
8
</intent-filter>
9
</receiver>
10
...
11
</application>
Copied!
Then add the code to the receiver.
Kotlin
Java
1
class LocationReceiver : RoamReceiver() {
2
override fun onLocationUpdated(context: Context?, roamLocation: RoamLocation?) {
3
// receive own location updates here
4
// do something with location data using location
5
}
6
}
Copied!
1
public class LocationReceiver extends RoamReceiver {
2
3
@Override
4
public void onLocationUpdated(Context context, RoamLocation roamLocation) {
5
// receive own location updates here
6
// do something with location data using location
7
}
8
}
Copied!
Get the current location of the user in the callback.
Kotlin
Java
1
Roam.getCurrentLocation(DesiredAccuracy, accuracy, object : RoamLocationCallback {
2
override fun location(location: Location?) {
3
// Access location data here
4
}
5
override fun onFailure(roamError: RoamError) {
6
// Access Error code and message here
7
// roamError.code
8
// roamError.message
9
}
10
})
Copied!
1
Roam.getCurrentLocation(DesiredAccuracy, accuracy, new RoamLocationCallback(){
2
@Override
3
public void location(Location location) {
4
// Access location data here
5
}
6
@Override
7
public void onFailure(RoamError roamError) {
8
// Access Error code and message here
9
// roamError.getCode();
10
// roamError.getMessage();
11
}
12
});
Copied!
Parameter
Description
DesiredAccuracy
RoamTrackingMode.DesiredAccuracy.HIGH RoamTrackingMode.DesiredAccuracy.MEDIUM RoamTrackingMode.DesiredAccuracy.LOW
Last modified 5mo ago
Copy link