SDK Methods

Listeners

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 toggle the location and event listener to true. By default, the status will set to false and needs to be set to true in order to stream the location and events updates to the same device or other devices.

GeoSpark.toggleListener(Events: true, Locations: true) { (geosparkUser, error) in
// access location lister status with geosparkUser?.locationListener
// access events lister status geosparkUser?.eventListener
// access geospark error code with error?.code
// access geospark error message with error?.message
}

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

GeoSpark.getListenerStatus({ (geosparkUser, error) in
// access location lister status with geosparkUser?.locationListener
// access events lister status geosparkUser?.eventListener
// access geospark error code with error?.code
// access geospark error message with error?.message
}

Subscribe to Location Updates and Events

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 event updates
GeoSpark.subscribeEvent()

To listen to location updates create a class that implements GeoSparkDelegate and then call GeoSpark.delegate.

Set yourGeoSparkDelegate in a code path that will be initialized and executed in the background. For example, make your AppDelegate implement GeoSparkDelegate, not a ViewController. AppDelegate will be initialized in the background, whereas a ViewController may not be.

class AppDelegate: UIResponder,UIApplicationDelegate,GeoSparkDelegate{
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey:
Any]?) -> Bool {
GeoSpark.initialize("YOUR SDK KEY GOES HERE")
GeoSpark.delegate = self
return true
}
func didUpdateLocation(_ geospark: GeoSparkLocation) {
//receive own location updates here
//do something with location data using location
}
func didReceiveUserLocation(_ dictionary: Dictionary<String, Any>) {
//receive other user's location updates here
//do something with location data dictionary
}
func didReceiveEvent(_ dictionary: Dictionary<String, Any>) {
//receive other user's location updates here
//do something with location data dictionary
}
func didReceiveTripStatus(_ tripStatus: TripStatusListener) {
//do something with trip status data
}
}

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 other event updates
GeoSpark.unSubscribeEvent()

You should also set the location and event listener to “false” if you wish not to stream the user location.

Toggle Event Flags

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

GeoSpark.toggleEvents(Geofence: true, Location: true, Trips: true, MovingGeofence: true { (GeoSparkUser, error) in
// access location events status with geosparkUser?.locationEvents
// access geofence events status with geosparkUser?.geofenceEvents
// access trips events status with geosparkUser?.tripsEvents
// access moving geofence events status with geosparkUser?.movingGeofenceEvents
// access geospark error code with error?.code
// access geospark error message with error?.message
}

Trips

Use the below code to create a trip directly from the SDK.

GeoSpark.createTrip { (GeoSparkTrip, error) in
// access geospark trip created timestamp with geosparkTrip?.createdAt
// access geospark trip user id with geosparkTrip?.userId
// access geospark trip id with geosparkTrip?.tripId
// access geospark error code with error?.code
// access geospark error message with error?.message
}

To get the trip details.

GeoSpark.getTripDetails("GEOSPARK-TRIP-ID") { (geosparkTrip, error) in
// access geospark trip created timestamp with geosparkTrip?.createdAt
// access geospark trip user id with geosparkTrip?.userId
// access geospark trip id with geosparkTrip?.tripId
// access geospark error code with error?.code
// access geospark error message with error?.message
}

To get the trip status.

GeoSpark.getTripStatus("GEOSPARK-TRIP-ID") { (geosparkTrip, error) in
// access geospark trip distance covered with geosparkTrip?.distance
// access geospark trip speed with geosparkTrip?.speed
// access geospark trip duration with geosparkTrip?.duration
// access geospark trip id with geosparkTrip?.tripId
// access geospark trip started timestamp with geosparkTrip?.startedAt
// access geospark error code with error?.code
// access geospark error message with error?.message
}

To get the trip summary.

GeoSpark.getTripSummary("GEOSPARK-TRIP-ID") { (geosparkTrip, error) in
// access geospark trip distance covered with geosparkTrip?.distanceCovered
// access geospark trip route with geosparkTrip?.route
// access geospark trip duration with geosparkTrip?.duration
// access geospark trip id with geosparkTrip?.tripId
// access geospark error code with error?.code
// access geospark error message with error?.message
}

To start the trip with the previously created trip id.

GeoSpark.startTrip("GEOSPARK-TRIP-ID") { (status, error) in
// access geospark trip status with status
// access geospark error code with error?.code
// access geospark error message with error?.message
}

To pause the trip with the previously started trip id.

GeoSpark.pauseTrip("GEOSPARK-TRIP-ID") { (status, error) in
// access geospark trip status with status
// access geospark error code with error?.code
// access geospark error message with error?.message
}

To resume the trip.

GeoSpark.resumeTrip("GEOSPARK-TRIP-ID") { (status, error) in
// access geospark trip status with status
// access geospark error code with error?.code
// access geospark error message with error?.message
}

To stop the trip.

GeoSpark.stopTrip("GEOSPARK-TRIP-ID") { (status, error) in
// access geospark trip status with status
// access geospark error code with error?.code
// access geospark error message with error?.message
}