-
Notifications
You must be signed in to change notification settings - Fork 5
SDK Methods
Now that the location tracking is set up, you can subscribe to locations and events and use the data locally on your device or send it directly to your own backend server.
To do that, you need to set the location and event listener to true
using the below method. By default the status will set false
and needs
to be set true
in order to stream the location and event updates to
the same device or other devices.
Roam.toggleListener(locations: true,events: true,callBack: ({user}) {
//Do something with user
print(user);
});
You can also get the current status of listeners with the below method.
Roam.getListenerStatus(callBack: ({user}) {
//Do something with user
print(user);
});
Now that you have enabled the location listener, use the below method to subscribe to your own or other user's location updates and events.
//subscribe to own location updates
Roam.subscribeLocation();
//subscribe to other user's location updates
Roam.subscribeUserLocation("ROAM-USER-ID");
//subscribe to trip status
Roam.subscribeTripStatus("ROAM-TRIP-ID");
You should set the location and event listener to false
if you do not
need to stream the user location.
To listen to events on the server-side, you should enable events for the user using the method below.
Roam.toggleEvents(location: true,geofence: true,trips: true,movingGeofence: true,callBack: ({user}) {
//Do something with user
print(user);
});
NOTE: Trips V1 is supported only up to 0.0.X. Trips V2 support starts from 0.1.X versions.
Use the below code to create a trip directly from the SDK. Set
Boolean value true
to create offline trip and false
to create
online trip.
Roam.createTrip(isOffline: false,callBack: ({trip}) {
//Do something with trip
print(trip);
});
Use the below code to start the trip with the previously created trip id.
Roam.startTrip(tripId: <TRIP-ID>);
Use the below code to pause the trip with the previously started trip id.
Roam.pauseTrip(tripId: <TRIP-ID>);
To resume the trip.
Roam.resumeTrip(tripId: <TRIP-ID>);
To end the trip.
Roam.endTrip(tripId: <TRIP-ID>);
To get the trip summary.
Roam.getTripSummary(tripId: <TRIP-ID>);
</div>
</div>
A RoamTrip
object must be passed for quickTrip.
Set isLocal Boolean value true
to create offline trip and false
to create
online trip.
Stops can be added using the stop
property of the RoamTrip
object.
Tracking mode for the trip can be set using the trackingMode
parameter.
RoamTrip quickTrip = RoamTrip(isLocal: false);
RoamTripStops stop = RoamTripStops(radius, [longitude,latitude]);
quickTrip.stop.add(stop);
Roam.startTrip(({roamTripResponse}) {
print(roamTripResponse?.toJson());
//do something with roamTripResponse object
}, ({error}) {
print(error?.toJson());
},
roamTrip: quickTrip,
roamTrackingMode: RoamTrackingMode.ACTIVE);
Roam has three default tracking modes along with a custom version.
RoamTrackingMode.ACTIVE
RoamTrackingMode.BALANCED
RoamTrackingMode.PASSIVE
Custom Tracking for android
RoamTrackingMode.time(updateInterval, desiredAccuracy: DesiredAccuracy.HIGH);
RoamTrackingMode.distance(distanceFilter, stopDuration, desiredAccuracy: DesiredAccuracy.HIGH);
Custom Tracking for iOS
RoamTrackingMode.customIOS(activityType, desiredAccuracyIOS, allowBackgroundLocationUpdates, pausesLocationUpdatesAutomatically, showsBackgroundLocationIndicator, accuracyFilter, distanceFilter, updateInterval);
Use the below code to create a trip using the RoamTrip
class. Set
Boolean isLocal value true
to create offline trip and false
to create
online trip.
Stops can be added using the stop
property of the RoamTrip
object.
RoamTrip roamTrip = RoamTrip(isLocal: false);
RoamTripStops stop = RoamTripStops(radius, [longitude,latitude]);
roamTrip.stop.add(stop);
Roam.createTrip(roamTrip, ({roamTripResponse}) {
print(roamTripResponse?.toJson());
//do something with roamTripResponse object
}, ({error}) {
String errorString = jsonEncode(error?.toJson());
print(errorString);
});
To start a previously created trip, pass the trip id
in startTrip
method
Roam.startTrip(({roamTripResponse}) {
print(roamTripResponse?.toJson());
//do something with roamTripResponse object
}, ({error}) {
print(error?.toJson());
},
tripId: tripId);
To update an existing trip, create a RoamTrip
object with isLocal
boolean value and tripID
.
RoamTrip updateTrip = RoamTrip(tripId: tripId);
updateTrip.isLocal = false;
updateTrip.description = "changed description";
Roam.updateTrip(updateTrip, ({roamTripResponse}) {
print(roamTripResponse?.toJson());
//do something with roamTripResponse object
}, ({error}) {
print(error?.toJson());
});
To pause a running trip, pass the trip id
to pauseTrip()
method.
Roam.pauseTrip(tripId, ({roamTripResponse}) {
print(roamTripResponse?.toJson());
//do something with roamTripResponse object
}, ({error}) {
print(error?.toJson());
To resume a paused trip, pass the trip id
to resumeTrip()
method.
Roam.resumeTrip(tripId, ({roamTripResponse}) {
print(roamTripResponse?.toJson());
//do something with roamTripResponse object
}, ({error}) {
print(error?.toJson());
});
To end an existing trip, pass the trip id
and bool value to stop tracking in endTrip()
method.
Roam.endTrip(tripId, false, ({roamTripResponse}) {
print(roamTripResponse?.toJson());
//do something with roamTripResponse object
}, ({error}) {
print(error?.toJson());
});
To delete a trip, pass the trip id
in deleteTrip()
method.
Roam.deleteTrip(tripId, ({roamDeleteTripResponse}) {
print(roamDeleteTripResponse?.toJson());
//do something with roamDeleteTripResponse object
}, ({error}) {
print(error?.toJson());
});
To sync an offline trip, pass the trip id
in the syncTrip
method.
Roam.syncTrip(tripId, ({roamSyncTripResponse}) {
print(roamSyncTripResponse?.toJson());
}, ({error}) {
print(error?.toJson());
});
To get details of a trip, pass the trip id
in getTrip()
method.
Roam.getTrip(tripId, ({roamTripResponse}) {
print(roamTripResponse?.toJson());
//do something with roamTripResponse object
}, ({error}) {
print(error?.toJson());
});
To get active trips, pass bool value as true
for offline trips and false
for online trips.
Roam.getActiveTrips(false, ({roamActiveTripResponse}) {
print(roamActiveTripResponse?.toJson());
}, ({error}) {
print(error?.toJson());
});
To get the trip summary with route coordinates, pass trip id
in the getTripSummary()
method.
Roam.getTripSummary(tripId, ({roamTripResponse}) {
print(roamTripResponse?.toJson());
}, ({error}) {
print(error?.toJson());
});
To subscribe to the real-time status of any ongoing trip, pass the trip id
in the subscribeTrip()
method.
Roam.subscribeTrip(tripId);
Roam.unsubscribeTrip(tripId);