Quickstart

The GeoSpark Android SDK makes it quick and easy to build a location tracker for your Android app. We provide powerful and customizable tracking modes and features.

Requirements

To use the GeoSpark SDK, the following things are required:

  • Get yourself a free GeoSpark Account. No credit card required.

  • Create a project and add an Android app to the project.

  • You need the SDK_KEY in your project settings which you’ll need to initialize the SDK.

  • Now, you’re ready to integrate the SDK into your Android application.

The GeoSpark Android SDK requires Android Studio 2.0 or later and is compatible with apps targeting Android SDK Version 16 or above.

Android Studio Setup

To use the Android SDK in a project, add the SDK as a build dependency and sync the project.

  1. Go to Android Studio > New Project > Minimum SDK

  2. Select API 16: Android 4.1.0 (Jelly Bean) or higher and create a project

  3. After you create a new project, open Gradle Scripts > build.gradle (Project: <your_project>) and do the following:

    1. Add the following to the build script {repositories {}} section of the build.gradle (Project)file:

      mavenCentral()

Sync and close build.gradle (Project: <your_project>)

Gradle Installation

Below steps to add SDK to the project using Gradle.

Add the below under the “dependencies” section of build.gradle file.

dependencies {
implementation'com.geospark.android:geospark:3.0.4'
}

Then sync Gradle.

Manual Installation

Download and unzip GeoSpark SDK

  1. Open Android Studio and add the SDK GeoSpark.aar as a module using File > New > New Module > Import .JAR/.AAR Package.

  2. Once Gradle is finished click File > Project Structure again.

  3. Click on the Dependencies tab > click App > click the “+” icon in the top left in Declared Dependencies section > select Module Dependency > click on GeoSpark-release > press Ok and wait for Gradle to sync again and include the dependencies separately and sync your project.

  4. Wait for Gradle to sync again and include the dependencies separately and sync your project.

dependencies {
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.2'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation('com.amazonaws:aws-android-sdk-iot:2.16.+@aar') { transitive = true }
implementation('com.amazonaws:aws-android-sdk-mobile-client:2.16.+@aar') { transitive = true }
}

Initialise SDK

Before initialising the SDK, the below must be imported.

import com.geospark.lib.GeoSpark;

After import, add the below code under the Application class onCreate() method. The SDK must be initialised before calling any of the other SDK methods.

Kotlin
Java
Kotlin
GeoSpark.initialize(this, "YOUR SDK KEY GOES HERE")
Java
GeoSpark.initialize(this, "YOUR SDK KEY GOES HERE");

Request Location Permission

To start tracking the location below Android 10.

Kotlin
Java
Kotlin
if (!GeoSpark.checkLocationPermission()) {
GeoSpark.requestLocationPermission(this)
} else if (!GeoSpark.checkLocationServices()) {
GeoSpark.requestLocationServices(this)
} else {
startTracking()
}
Java
if (!GeoSpark.checkLocationPermission()) {
GeoSpark.requestLocationPermission(this);
} else if (!GeoSpark.checkLocationServices()) {
GeoSpark.requestLocationServices(this);
} else {
startTracking();
}

To start tracking the location in Android 10 and above.

Kotlin
Java
Kotlin
if (!GeoSpark.checkLocationPermission()) {
GeoSpark.requestLocationPermission(this)
} else if (!GeoSpark.checkBackgroundLocationPermission()) {
GeoSpark.requestBackgroundLocationPermission(this)
} else if (!GeoSpark.checkLocationServices()) {
GeoSpark.requestLocationServices(this)
} else {
startTracking()
}
Java
if (!GeoSpark.checkLocationPermission()) {
GeoSpark.requestLocationPermission(this);
} else if (!GeoSpark.checkBackgroundLocationPermission()) {
GeoSpark.requestBackgroundLocationPermission(this);
} else if (!GeoSpark.checkLocationServices()) {
GeoSpark.requestLocationServices(this);
} else {
startTracking()
}

Tracking Modes

GeoSpark has three default tracking modes along with a custom version. They differ based on the frequency of location updates and battery consumption. The higher the frequency, the higher is the battery consumption. You must use foreground service for continuous tracking.

Mode

Battery usage

Updates every

Optimised for/advised for

Active

6% - 12%

25 ~ 250 meters

Ride Hailing / Sharing

Reactive

3% - 6%

50 ~ 500 meters

On Demand Services

Passive

0% - 1%

100 ~ 1000 meters

Social Apps

Use the tracking modes while you use the startTracking method GeoSpark.startTracking or GeoSpark.startSelfTracking

Example:

For reference check our sample app : https://github.com/geosparks/geospark-android-sdk-example

Kotlin
Java
Kotlin
//cloud integration
//active tracking
GeoSpark.startTracking(GeoSparkTrackingMode.ACTIVE)
// reactive tracking
GeoSpark.startTracking(GeoSparkTrackingMode.REACTIVE)
// active tracking
GeoSpark.startTracking(GeoSparkTrackingMode.ACTIVE)
//self-managed integration
//active tracking
GeoSpark.startSelfTracking(GeoSparkTrackingMode.ACTIVE)
// reactive tracking
GeoSpark.startSelfTracking(GeoSparkTrackingMode.REACTIVE)
// active tracking
GeoSpark.startSelfTracking(GeoSparkTrackingMode.ACTIVE)
Java
//cloud integration
//active tracking
GeoSpark.startTracking(GeoSparkTrackingMode.ACTIVE);
// reactive tracking
GeoSpark.startTracking(GeoSparkTrackingMode.REACTIVE);
// active tracking
GeoSpark.startTracking(GeoSparkTrackingMode.ACTIVE);
//self-managed integration
//active tracking
GeoSpark.startSelfTracking(GeoSparkTrackingMode.ACTIVE);
// reactive tracking
GeoSpark.startSelfTracking(GeoSparkTrackingMode.REACTIVE);
// active tracking
GeoSpark.startSelfTracking(GeoSparkTrackingMode.ACTIVE);

Custom Tracking Modes

The SDK also provides a custom tracking mode that allows you to customize and build your own tracking modes.

Type

Unit

Unit Range

Distance Interval

Meters

1m ~ 2500m

Time Interval

Seconds

10s ~ 10800s

Distance between location updates example code:

Kotlin
Java
Kotlin
//Update location based on distance between locations.
val trackingMode = GeoSparkTrackingMode.Builder("DISTANCE IN METERS", "STATIONARY DURATION IN SECONDS")
.setDesiredAccuracy(GeoSparkTrackingMode.DesiredAccuracy.HIGH)
.build()
Java
//Update location based on distance between locations.
GeoSparkTrackingMode trackingMode = new GeoSparkTrackingMode.Builder("DISTANCE IN METERS", "STATIONARY DURATION IN SECONDS")
.setDesiredAccuracy(GeoSparkTrackingMode.DesiredAccuracy.HIGH)
.build();

Time between location updates example code:

Kotlin
Java
Kotlin
//Update location based on time interval.
val trackingMode = GeoSparkTrackingMode.Builder("INTERVAL IN SECONDS")
.setDesiredAccuracy(GeoSparkTrackingMode.DesiredAccuracy.HIGH)
.build()
Java
//Update location based on time interval.
GeoSparkTrackingMode trackingMode = new GeoSparkTrackingMode.Builder("INTERVAL IN SECONDS")
.setDesiredAccuracy(GeoSparkTrackingMode.DesiredAccuracy.HIGH)
.build();

Next Steps

  • Cloud Integration Cloud integration is when we manage your data through our servers providing you a system of tools and technologies that connects various applications and systems for the real-time exchange of location data and processes including Insights, Trips, Geofencing and Nearby APIs.

    or”

  • Self-Managed Integration Self-managed integration is when you manage your data by sending all location data back to your server from the SDK directly without communicating to our server. This allows you to keep complete privacy of your data and manage your security standards.