Skip to content

SDK Methods

Ekambaram edited this page Feb 22, 2021 · 4 revisions

Listeners

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
});

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');  

Toggle Event Flags

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
});

Trips

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
});

Subscribe Trip Status

Subscribe to tripStatus using tripId to get real time trip status.

//subscribe to trip status
GeoSpark.subscribeTripStatus("GeoSpark Trip ID");

To stop receiving trip status updates, use the below method.

//unsubscribe to trip status
GeoSpark.unSubscribeTripStatus("GeoSpark Trip ID");

Clone this wiki locally