-
Notifications
You must be signed in to change notification settings - Fork 0
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 events updates to
the same device or other devices.
GeoSpark.toggleListener(locations, events, success => {
// do something on success
},
error => {
// do something on error
});You can also get the current status of listeners with the below method.
GeoSpark.getListenerStatus(success => {
// do something on success
},
error => {
// do something on error
});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
GeoSpark.subscribeLocation();
//subscribe to other user's location updates
GeoSpark.subscribeUserLocation("GeoSpark User ID");
//subscribe to trip status
GeoSpark.subscribeTripStatus("GeoSpark Trip ID");To listen to location updates
You only need to call these methods once, as these settings will be persisted across App sessions.
To listen for location updates, you can add event listeners:
GeoSpark.startListener('location', (result) => {
// do something with location
});To listen for location received updates, you can add event listeners:
GeoSpark.startListener('location_received', (result) => {
// do something with location
});To listen for trip status updates, you can add event listeners:
GeoSpark.startListener('trip_status', (result) => {
// do something with trip_status
});To listen for error updates, you can add event listeners:
GeoSpark.startListener('error', (result) => {
// do something with error
});Add event listeners outside of your component lifecycle (e.g., outside
of componentDidMount) if you want them to work when the app is in the
background.
You can also remove event listeners:
//Stop location updates
GeoSpark.stopListener('location');
//Stop location received updates
GeoSpark.stopListener('location_received');
//Stop trip updates
GeoSpark.stopListener('trip_status');
//Stop error updates
GeoSpark.stopListener('error'); To stop receiving location updates, use the below method.
//unsubscribe to own location updates
GeoSpark.unSubscribeLocation();
//unsubscribe to other user's location updates
GeoSpark.unSubscribeUserLocation("GeoSpark User ID");
//unsubscribe to trip status
GeoSpark.unSubscribeTripStatus("GeoSpark 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.
GeoSpark.toggleEvents(geofence, trip, location, movingGeofence, success => {
// do something on success
},
error => {
// do something on error
});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.
GeoSpark.createTrip(offline, success => {
// do something on success
},
error => {
// do something on error
});To get the active trips. Set Boolean value true to get offline
trips and false to get online trips.
GeoSpark.activeTrips(offline, success => {
// do something on success
},
error => {
// do something on error
});Use the below code to start the trip with the previously created trip id.
GeoSpark.startTrip("GEOSPARK-TRIP-ID", "GEOSPARK-TRIP-DESCRIPTION", success => {
// do something on success
},
error => {
// do something on error
});Use the below code to pause the trip with the previously started trip id.
GeoSpark.pauseTrip("GEOSPARK-TRIP-ID", success => {
// do something on success
},
error => {
// do something on error
});To resume the trip.
GeoSpark.resumeTrip("GEOSPARK-TRIP-ID", success => {
// do something on success
},
error => {
// do something on error
});To stop the trip.
GeoSpark.stopTrip("GEOSPARK-TRIP-ID", success => {
// do something on success
},
error => {
// do something on error
});