For reference check our sample app and ensure all the 10 TODO Steps:--https://github.com/geosparks/geospark-android-migration-example ​
Note:(After updating SDK from 2.2.5 to 3.0.4)
After initialising SDK :-
Add the below code under the Application class onCreate() method.
public class MainApplication extends Application {@Overridepublic void onCreate() {super.onCreate();GeoSpark.initialize(this,"YOUR-PUBLISHABLE-KEY");//Add the below codeGeoSpark.setTrackingInAppState(GeoSparkTrackingMode.AppState.ALWAYS_ON);GeoSpark.locationPublisher(true);GeoSpark.offlineLocationTracking(true);}}
The following methods do not require context.
createUser("SET USER DESCRIPTION HERE", new GeoSparkCallback());​getUser(GEOSPARK USER ID", new GeoSparkCallback());​setDescription("SET USER DESCRIPTION HERE");​toggleEvents(geofence, trip, location, movingGeofence, new GeoSparkCallback());​getEventsStatus(new GeoSparkCallback());
checkLocationPermission();​checkLocationServices();​checkBackgroundLocationPermission();
isLocationTracking();​startTracking(TrackingMode);​stopTracking();​getCurrentLocation(accuracy, new GeoSparkLocationCallback());​updateCurrentLocation(accuracy);
startTrip(String message);​stopTrip(String message);​activeTrips(new GeoSparkActiveTripsCallback());
logout(new GeoSparkLogoutCallBack());​setDeviceToken("FCM DeviceToken");​getDeviceToken();​notificationOpenedHandler(getIntent());​disableBatteryOptimization();​isBatteryOptimizationEnabled();
We have removed the success and failure callback function.
GeoSpark.setDescription( "User Description");
To listen to events on the server-side, you should enable geofence, trip, location and movingGeofence events for the user using the method below.
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}});
We have introduced new tracking modes in v3, with the following presets:
Passive
Active
Reactive
Custom
/*You can now start tracking your users. GeoSpark has three default trackingmodes.*/​GeoSpark.startTracking(GeoSparkTrackingMode.PASSIVE);GeoSpark.startTracking(GeoSparkTrackingMode.REACTIVE);GeoSpark.startTracking(GeoSparkTrackingMode.ACTIVE);​/* The SDK also provides a custom tracking mode that allows youto customize and build your own tracking mode.*/​GeoSparkTrackingMode trackingMode = new GeoSparkTrackingMode.Builder().setDesiredAccuracy(GeoSparkTrackingMode.DesiredAccuracy.HIGH).setStopDuration("DURATION IN SECONDS").setDistanceFilter("DISTANCE IN METERS").build();GeoSpark.startTracking(trackingMode);
To listen to your own or other user's location updates, create a class that extends GeoSparkReceiver.
public class MyGeoSparkReceiver extends GeoSparkReceiver {@Overridepublic void onLocationUpdated(Context context, String json){// receive own location updates here// do something with location data using json}@Overridepublic void onLocationReceived(Context context, String json) {// receive other user's location updates here// do something with json}@Overridepublic void onReceiveTripStatus(Context context, TripStatusListener listener) {// receive real time trip status here// do something with trip status data}​@Overridepublic void onEventReceived(Context context, String json) {//access event data here}​@Overridepublic void onError(Context context, GeoSparkError geosparkError) {//access error data here}}
Get the current location of the user. You can set the accuracy between 10 to 100 meters (default is 10).
GeoSpark.getCurrentLocation(DesiredAccuracy, Accuracy, new GeoSparkLocationCallback(){@Overridepublic void location(Location location) {// do something with location data using location}​@Overridepublic void onFailure(GeoSparkError geoSparkError) {//access error data here}});
​
Parameter | Description |
DesiredAccuracy | GeoSparkTrackingMode.DesiredAccuracy.HIGH (or) GeoSparkTrackingMode.DesiredAccuracy.MEDIUM (or) GeoSparkTrackingMode.DesiredAccuracy.LOW |
Using the updateCurrentLocation
method, you can update the user's current location, you can set the accuracy between 10 to 100 meters (default is 10).
GeoSpark.updateCurrentLocation(DesiredAccuracy, accuracy);
Parameter | Description |
DesiredAccuracy | GeoSparkTrackingMode.DesiredAccuracy.HIGH (or) GeoSparkTrackingMode.DesiredAccuracy.MEDIUM (or) GeoSparkTrackingMode.DesiredAccuracy.LOW |
Get online and offline active trips using the activeTrips()
method.
GeoSpark.activeTrips(boolean, new GeoSparkActiveTripsCallback() {@Overridepublic void onSuccess(GeoSparkTrip geoSparkTrip) {//access geospark trips geoSparkTrip.getActiveTrips();}​@Overridepublic void onFailure(GeoSparkError geoSparkError) {//access error data here}});
Parameter | Description |
Boolean | true for offline trips false for online trips |
Renamed from endTrip to stopTrip.
GeoSpark.stopTrip("GEOSPARK-TRIP-ID", new GeoSparkTripCallback() {@Overridepublic void onSuccess(String message) {}@Overridepublic void onFailure(GeoSparkError geosparkError) {//access error data here}});