You can also get the current status of listeners with the below method.
GeoSpark.getListenerStatus(object : GeoSparkCallback {override fun onSuccess(geosparkUser: GeoSparkUser) {// do something when get listener status success// get location listener status with geosparkUser.getLocationListenerStatus// get events listener status with geosparkUser.getEventListenerStatus}override fun onFailure(geosparkError: GeoSparkError) {// do something when get listener status failure}})
GeoSpark.getListenerStatus(new GeoSparkCallback() {@Overridepublic void onSuccess(GeoSparkUser geosparkUser) {// do something when get listener status success// get location listener status with geosparkUser.getLocationListenerStatus// get events listener status with geosparkUser.getEventListenerStatus}@Overridepublic void onFailure(GeoSparkError geosparkError ) {// do something when get listener status failure}});
To listen to location updates create a class that extends GeoSparkReceiver. Then register the receiver by adding a receiver element to the application element in your manifest.
<application>...<receiver android:name=".MyGeoSparkReceiver"android:enabled="true"android:exported="false"><intent-filter><action android:name="com.geospark.android.RECEIVED"/></intent-filter></receiver>...</application>
Then add the code to the receiver.
public class MyGeoSparkReceiver : GeoSparkReceiver() {override fun onLocationUpdated(context: Context, geosparkLocation: GeoSparkLocation) {// receive own location updates here// do something with location data using location}override fun onLocationReceived(context: Context, geosparkLocationReceived: GeoSparkLocationReceived) {// receive other user's location updates here// do something with location}override fun onEventReceived(context: Context, geoSparkEvent: GeoSparkEvent) {//access event data here}override fun onReceiveTripStatus(context: Context, listener: TripStatusListener) {// receive real time trip status here// do something with trip status data}override fun onError(context: Context, geosparkError: GeoSparkError) {//access error data here}}
public class MyGeoSparkReceiver extends GeoSparkReceiver {@Overridepublic void onLocationUpdated(Context context, GeoSparkLocation geosparkLocation) {// receive own location updates here// do something with location data using location}@Overridepublic void onLocationReceived(Context context, GeoSparkLocationReceived geosparkLocationReceived) {// receive other user's location updates here// do something with location}@Overridepublic void onEventReceived(Context context, GeoSparkEvent geoSparkEvent) {//access event data here}@Overridepublic void onReceiveTripStatus(Context context, TripStatusListener listener) {// receive real time trip status here// do something with trip status data}@Overridepublic void onError(Context context, GeoSparkError geosparkError) {//access error data here}}
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, object : GeoSparkCallback {override fun onSuccess(geosparkUser: GeoSparkUser) {// do something when toggle events success// access location events status with geosparkUser.getLocationEvents()// access geofence events status with geosparkUser.getGeofenceEvents()// access trips events status with geosparkUser.getTripsEvents()// get moving geofence event status with geosparkUser.getMovingGeofenceEvents()}override fun onFailure(error: GeoSparkError) {// do something when toggle events failure}})
GeoSpark.toggleEvents(geofence, trip, location, movingGeofence, new GeoSparkCallback() {@Overridepublic void onSuccess(GeoSparkUser geosparkUser) {// do something when toggle events success// access location events status with geosparkUser.getLocationEvents()// access geofence events status with geosparkUser.getGeofenceEvents()// access trips events status with geosparkUser.getTripsEvents()// get moving geofence event status with geosparkUser.getMovingGeofenceEvents()}@Overridepublic void onFailure(GeoSparkError error ) {// do something when toggle events failure}});
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(null, null, Boolean, object : GeoSparkCreateTripCallback {override fun onSuccess(geosparkTrip: GeoSparkCreateTrip) {// do something when create trip success// access geospark trip created timestamp with geosparkTrip.getCreatedAt// access geospark trip user id with geosparkTrip.getUserId// access geospark trip id with geosparkTrip.getTripId}override fun onFailure(geosparkError: GeoSparkError) {// do something when create trip error// access geospark error code with geosparkError.getCode()// access geospark error message with geosparkError.getMessage()}})
GeoSpark.createTrip(null, null, Boolean, new GeoSparkCreateTripCallback() {@Overridepublic void onSuccess(GeoSparkCreateTrip geosparkTrip) {// do something when create trip success// access geospark trip created timestamp with geosparkTrip.getCreatedAt// access geospark trip user id with geosparkTrip.getUserId// access geospark trip id with geosparkTrip.getTripId}@Overridepublic void onFailure(GeoSparkError geosparkError) {// do something when create trip error// access geospark error code with geosparkError.getCode()// access geospark error message with geosparkError.getMessage()}});
To get the trip details.
GeoSpark.getTripDetails("GEOSPARK-TRIP-ID", object : GeoSparkTripDetailCallback {override fun onSuccess(geosparkTrip: GeoSparkTripDetail) {// do something when get trip details success// access geospark trip created timestamp with geosparkTrip.getCreatedAt()// access geospark trip user id with geosparkTrip.getUserId()// access geospark trip id with geosparkTrip.getTripId()}override fun onFailure(geosparkError: GeoSparkError) {// do something when get trip details error// access geospark error code with geosparkError.getCode()// access geospark error message with geosparkError.getMessage()}})
GeoSpark.getTripDetails("GEOSPARK-TRIP-ID", new GeoSparkTripDetailCallback() {@Overridepublic void onSuccess(GeoSparkTripDetail geosparkTrip) {// do something when get trip details success// access geospark trip created timestamp with geosparkTrip.getCreatedAt()// access geospark trip user id with geosparkTrip.getUserId()// access geospark trip id with geosparkTrip.getTripId()}@Overridepublic void onFailure(GeoSparkError geosparkError) {// do something when get trip details error// access geospark error code with geosparkError.getCode()// access geospark error message with geosparkError.getMessage()}});
To get the trip status.
GeoSpark.getTripStatus("GEOSPARK-TRIP-ID", object : GeoSparkTripStatusCallback {override fun onSuccess(geosparkTrip: GeoSparkTripStatus) {// do something when get trip details success// access geospark trip distance with geosparkTrip.getDistance()// access geospark trip speed with geosparkTrip.getSpeed()}override fun onFailure(geosparkError: GeoSparkError) {// do something when get trip details error// access geospark error code with geosparkError.getCode()// access geospark error message with geosparkError.getMessage()}})
GeoSpark.getTripStatus("GEOSPARK-TRIP-ID", new GeoSparkTripStatusCallback() {@Overridepublic void onSuccess(GeoSparkTripStatus geosparkTrip) {// do something when get trip details success// access geospark trip distance with geosparkTrip.getDistance()// access geospark trip speed with geosparkTrip.getSpeed()}@Overridepublic void onFailure(GeoSparkError geosparkError) {// do something when get trip details error// access geospark error code with geosparkError.getCode()// access geospark error message with geosparkError.getMessage()}});
To get the trip summary.
GeoSpark.getTripSummary("GEOSPARK-TRIP-ID", object : GeoSparkTripSummaryCallback {override fun onSuccess(geosparkTrip: GeoSparkTripSummary) {// do something when get trip details success// access geospark trip distance covered with geosparkTrip.getDistanceCovered// access geospark trip route with geosparkTrip.getRoute// access geospark trip duration with geosparkTrip.getDuration// access geospark trip id with geosparkTrip.getTripId}override fun onFailure(geosparkError: GeoSparkError) {// do something when get trip details error// access geospark error code with geosparkError.getCode()// access geospark error message with geosparkError.getMessage()}})
GeoSpark.getTripSummary("GEOSPARK-TRIP-ID", new GeoSparkTripSummaryCallback() {@Overridepublic void onSuccess(GeoSparkTripSummary geosparkTrip) {// do something when get trip details success// access geospark trip distance covered with geosparkTrip.getDistanceCovered// access geospark trip route with geosparkTrip.getRoute// access geospark trip duration with geosparkTrip.getDuration// access geospark trip id with geosparkTrip.getTripId}@Overridepublic void onFailure(GeoSparkError geosparkError) {// do something when get trip details error// access geospark error code with geosparkError.getCode()// access geospark error message with geosparkError.getMessage()}});
To get the active trips. Set Boolean value true
to get offline trips and false
to get online trips.
GeoSpark.activeTrips(Boolean, object : GeoSparkActiveTripsCallback {override fun onSuccess(geoSparkTrip: GeoSparkTrip) {geoSparkTrip.activeTrips}override fun onFailure(geoSparkError: GeoSparkError) {geoSparkError.codegeoSparkError.message}})
GeoSpark.activeTrips(Boolean, new GeoSparkActiveTripsCallback() {@Overridepublic void onSuccess(GeoSparkTrip geoSparkTrip) {geoSparkTrip.getActiveTrips();}@Overridepublic void onFailure(GeoSparkError geoSparkError) {geoSparkError.getCode();geoSparkError.getMessage();}});
Use the below code to start the trip with the previously created trip id.
GeoSpark.startTrip("GEOSPARK-TRIP-ID", "GEOSPARK-TRIP-DESCRIPTION", object : GeoSparkTripCallback {override fun onSuccess(message: String) {}override fun onFailure(geosparkError: GeoSparkError) {// do something when start trip details error// access geospark error code with geosparkError.getCode()// access geospark error message with geosparkError.getMessage()}})
GeoSpark.startTrip("GEOSPARK-TRIP-ID", "GEOSPARK-TRIP-DESCRIPTION", new GeoSparkTripCallback() {@Overridepublic void onSuccess(String message) {}@Overridepublic void onFailure(GeoSparkError geosparkError) {// do something when start trip details error// access geospark error code with geosparkError.getCode()// access geospark error message with geosparkError.getMessage()}});
Use the below code to pause the trip with the previously started trip id.
GeoSpark.pauseTrip("GEOSPARK-TRIP-ID", object : GeoSparkTripCallback {override fun onSuccess(message: String) {}override fun onFailure(geosparkError: GeoSparkError) {// do something when start trip details error// access geospark error code with geosparkError.getCode()// access geospark error message with geosparkError.getMessage()}})
GeoSpark.pauseTrip("GEOSPARK-TRIP-ID", new GeoSparkTripCallback() {@Overridepublic void onSuccess(String message) {}@Overridepublic void onFailure(GeoSparkError geosparkError) {// do something when start trip details error// access geospark error code with geosparkError.getCode()// access geospark error message with geosparkError.getMessage()}});
To resume the trip.
GeoSpark.resumeTrip("GEOSPARK-TRIP-ID", object : GeoSparkTripCallback {override fun onSuccess(message: String) {}override fun onFailure(geosparkError: GeoSparkError) {// do something when start trip details error// access geospark error code with geosparkError.getCode()// access geospark error message with geosparkError.getMessage()}})
GeoSpark.resumeTrip("GEOSPARK-TRIP-ID", new GeoSparkTripCallback() {@Overridepublic void onSuccess(String message) {}@Overridepublic void onFailure(GeoSparkError geosparkError) {// do something when start trip details error// access geospark error code with geosparkError.getCode()// access geospark error message with geosparkError.getMessage()}});
To stop the trip.
GeoSpark.stopTrip("GEOSPARK-TRIP-ID", object : GeoSparkTripCallback {override fun onSuccess(message: String) {}override fun onFailure(geosparkError: GeoSparkError) {// do something when start trip details error// access geospark error code with geosparkError.getCode()// access geospark error message with geosparkError.getMessage()}})
GeoSpark.stopTrip("GEOSPARK-TRIP-ID", new GeoSparkTripCallback() {@Overridepublic void onSuccess(String message) {}@Overridepublic void onFailure(GeoSparkError geosparkError) {// do something when start trip details error// access geospark error code with geosparkError.getCode()// access geospark error message with geosparkError.getMessage()}});
Subscribe to tripStatus using tripId to get real time trip status.
//subscribe to trip statusGeoSpark.subscribeTripStatus("GeoSpark Trip ID")
//subscribe to trip statusGeoSpark.subscribeTripStatus("GeoSpark Trip ID");
To stop receiving trip status updates, use the below method.
//unsubscribe to trip statusGeoSpark.unSubscribeTripStatus("GeoSpark Trip ID")
//unsubscribe to trip statusGeoSpark.unSubscribeTripStatus("GeoSpark Trip ID");
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.
Callback Method which returns the current location with faster response time and the accuracy depends on the current GPS connectivity.
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 couple of seconds based on the GPS and network connectivity.
GeoSpark.getCurrentLocation(accuracy)
GeoSpark.getCurrentLocation(accuracy);
To listen to location update create a class that extends GeoSparkReceiver. Then register the receiver by adding a receiver element to the application element in your manifest.
<application>...<receiver android:name=".MyGeoSparkReceiver"android:enabled="true"android:exported="false"><intent-filter><action android:name="com.geospark.android.RECEIVED"/></intent-filter></receiver>...</application>
Then add the code to the receiver.
class MyGeoSparkReceiver : GeoSparkReceiver() {override fun onLocationUpdated(context: Context?, geosparkLocation: GeoSparkLocation?) {// receive own location updates here// do something with location data using location}}
public class MyGeoSparkReceiver extends GeoSparkReceiver {@Overridepublic void onLocationUpdated(Context context, GeoSparkLocation geosparkLocation) {// receive own location updates here// do something with location data using location}}
Get the current location of the user in callback.
GeoSpark.getCurrentLocation(DesiredAccuracy, accuracy, object : GeoSparkLocationCallback {override fun location(location: Location?) {}override fun onFailure(geoSparkError: GeoSparkError) {geoSparkError.codegeoSparkError.message}})
GeoSpark.getCurrentLocation(DesiredAccuracy, accuracy, new GeoSparkLocationCallback(){@Overridepublic void location(Location location) {}@Overridepublic void onFailure(GeoSparkError geoSparkError) {geoSparkError.getCode();geoSparkError.getMessage();}});
Parameter | Description |
DesiredAccuracy | GeoSparkTrackingMode.DesiredAccuracy.HIGH or GeoSparkTrackingMode.DesiredAccuracy.MEDIUM or GeoSparkTrackingMode.DesiredAccuracy.LOW |