SDK Methods

Listeners

You can also get the current status of listeners with the below method.

Kotlin
Java
Kotlin
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
}
})
Java
GeoSpark.getListenerStatus(new GeoSparkCallback() {
@Override
public 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
}
@Override
public 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.

Kotlin
Java
Kotlin
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
}
}
Java
public class MyGeoSparkReceiver extends GeoSparkReceiver {
@Override
public void onLocationUpdated(Context context, GeoSparkLocation geosparkLocation) {
// receive own location updates here
// do something with location data using location
}
@Override
public void onLocationReceived(Context context, GeoSparkLocationReceived geosparkLocationReceived) {
// receive other user's location updates here
// do something with location
}
@Override
public void onEventReceived(Context context, GeoSparkEvent geoSparkEvent) {
//access event data here
}
@Override
public void onReceiveTripStatus(Context context, TripStatusListener listener) {
// receive real time trip status here
// do something with trip status data
}
@Override
public void onError(Context context, GeoSparkError geosparkError) {
//access error data here
}
}

Toggle Event Flags

To listen to events on the server-side, you should enable events for the user using the method below.

Kotlin
Java
Kotlin
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
}
})
Java
GeoSpark.toggleEvents(geofence, trip, location, movingGeofence, new GeoSparkCallback() {
@Override
public 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()
}
@Override
public void onFailure(GeoSparkError error ) {
// do something when toggle events failure
}
});

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.

Kotlin
Java
Kotlin
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()
}
})
Java
GeoSpark.createTrip(null, null, Boolean, new GeoSparkCreateTripCallback() {
@Override
public 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
    }
@Override
     public 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.

Kotlin
Java
Kotlin
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()
}
})
Java
GeoSpark.getTripDetails("GEOSPARK-TRIP-ID", new GeoSparkTripDetailCallback() {
           @Override
           public 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()
           }
           @Override
           public 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.

Kotlin
Java
Kotlin
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()
}
})
Java
GeoSpark.getTripStatus("GEOSPARK-TRIP-ID", new GeoSparkTripStatusCallback() {
           @Override
           public 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()
           }
           @Override
           public 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.

Kotlin
Java
Kotlin
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()
}
})
Java
GeoSpark.getTripSummary("GEOSPARK-TRIP-ID", new GeoSparkTripSummaryCallback() {
           @Override
           public 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
           }
           @Override
           public 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.

Kotlin
Java
Kotlin
GeoSpark.activeTrips(Boolean, object : GeoSparkActiveTripsCallback {
override fun onSuccess(geoSparkTrip: GeoSparkTrip) {
geoSparkTrip.activeTrips
}
override fun onFailure(geoSparkError: GeoSparkError) {
geoSparkError.code
geoSparkError.message
}
})
Java
GeoSpark.activeTrips(Boolean, new GeoSparkActiveTripsCallback() {
@Override
public void onSuccess(GeoSparkTrip geoSparkTrip) {
geoSparkTrip.getActiveTrips();
}
@Override
public void onFailure(GeoSparkError geoSparkError) {
geoSparkError.getCode();
geoSparkError.getMessage();
}
});

Use the below code to start the trip with the previously created trip id.

Kotlin
Java
Kotlin
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()
}
})
Java
GeoSpark.startTrip("GEOSPARK-TRIP-ID", "GEOSPARK-TRIP-DESCRIPTION", new GeoSparkTripCallback() {
           @Override
           public void onSuccess(String message) {
           }
           @Override
           public 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.

Kotlin
Java
Kotlin
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()
}
})
Java
GeoSpark.pauseTrip("GEOSPARK-TRIP-ID", new GeoSparkTripCallback() {
           @Override
           public void onSuccess(String message) {
           }
           @Override
           public 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.

Kotlin
Java
Kotlin
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()
}
})
Java
GeoSpark.resumeTrip("GEOSPARK-TRIP-ID", new GeoSparkTripCallback() {
     @Override
public void onSuccess(String message) {
     }
@Override
     public 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.

Kotlin
Java
Kotlin
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()
}
})
Java
GeoSpark.stopTrip("GEOSPARK-TRIP-ID", new GeoSparkTripCallback() {
       @Override
       public void onSuccess(String message) {
       }
       @Override
       public 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 Trip Status

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

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

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

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

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. Callback Method which returns the current location with faster response time and the accuracy depends on the current GPS connectivity.

  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 couple of seconds based on the GPS and network connectivity.

Kotlin
Java
Kotlin
GeoSpark.getCurrentLocation(accuracy)
Java
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.

Kotlin
Java
Kotlin
class MyGeoSparkReceiver : GeoSparkReceiver() {
override fun onLocationUpdated(context: Context?, geosparkLocation: GeoSparkLocation?) {
// receive own location updates here
// do something with location data using location
}
}
Java
public class MyGeoSparkReceiver extends GeoSparkReceiver {
@Override
public 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.

Kotlin
Java
Kotlin
GeoSpark.getCurrentLocation(DesiredAccuracy, accuracy, object : GeoSparkLocationCallback {
override fun location(location: Location?) {
}
override fun onFailure(geoSparkError: GeoSparkError) {
geoSparkError.code
geoSparkError.message
}
})
Java
GeoSpark.getCurrentLocation(DesiredAccuracy, accuracy, new GeoSparkLocationCallback(){
@Override
public void location(Location location) {
}
@Override
public void onFailure(GeoSparkError geoSparkError) {
geoSparkError.getCode();
geoSparkError.getMessage();
}
});

Parameter

Description

DesiredAccuracy

GeoSparkTrackingMode.DesiredAccuracy.HIGH or GeoSparkTrackingMode.DesiredAccuracy.MEDIUM or GeoSparkTrackingMode.DesiredAccuracy.LOW