Android SDK

Setup the Woosmap Geofencing SDK using Android SDK

  1. Install SDK
  2. Dependencies
  3. Initialize SDK

The Woosmap Geofencing SDK allows you to monitor Geofences, track your user’s location and connect with the Woosmap Search and Distance APIs.

Learn how to integrate the Android SDK below. You can also explore the source code on GitHub to get deeper into it.

Install SDK

You can install the SDK using Gradle or manually.

We recommend implementing it using Gradle via https://jitpack.io.

Gradle via JitPack

Add the JitPack repository to your build.gradle file at the end of repositories, and add the dependency as follows:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
dependencies {
    implementation 'com.github.woosmap:woosmap-geofencing-android-sdk:1.2.1'
}

Install Manually

You can also add the SDK to your project manually.

Dependencies

The SDK requires Android 9 or newer, Google Play Services Location, and the open source Java library https://www.ojalgo.org/ used for matrix and equations calculations.

The SDK currently supports API level 28 and higher.

Initialize SDK

To retrieve your user’s location data when your app starts, initialize the SDK in MainActivity through the onCreate() method.

import com.webgeoservices.woosmapgeofencing.Woosmap;

public class MainActivity extends AppCompatActivity {
    private Woosmap woosmap;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate();
        
        this.woosmap = Woosmap.getInstance().initializeWoosmap(this);
        this.woosmap.setLocationReadyListener(new WoosLocationReadyListener());    
    }
}

Then, create a Listener connect to the interface Woosmap.LocationReadyListener and set a callback to retrieve user current location.

public class WoosLocationReadyListener implements Woosmap.LocationReadyListener {
    public void LocationReadyCallback(Location location) {
      onLocationCallback(location);
    }
}
private void onLocationCallback(Location currentLocation) {
    //Work with the user Location here
}

To get location consistently, call woosmap.onResume() and woosmap.onPause() functions on corresponding method of the App Activity Lifecycle.

@Override
public void onResume() {
    super.onResume();
    if (checkPermissions()) {    //Permission to get Location OK
        this.woosmap.onResume(); 
    } else {                     //Not alowed so Ask to Share Location
        requestPermissions(); 
    }
}

@Override
public void onPause(){
    super.onPause();
    if (checkPermissions()) {
        this.woosmap.onPause(); //Get Location In Background
    }
}
Was this article helpful?
Have more questions? Submit a request