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 a part of the source code on GitHub to get deeper into how user location is collected.

Find the release notes for the Geofencing Android SDK here.

Install SDK

You can install the SDK using Gradle. Note that the SDK is small and adds 400 KB to your compiled app. Geofencing SDK along with it’s dependencies adds an overhead of around 4 MB to the compiled APK.

Gradle via Maven central

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

gradle
        dependencies {
    implementation 'com.webgeoservices.woosmapgeofencing:woosmap-mobile-sdk:+'
}

    

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.

java
        import com.webgeoservices.woosmapgeofencing.Woosmap;
import com.webgeoservices.woosmapgeofencing.WoosmapSettings;
import com.webgeoservices.woosmapgeofencingcore.database.*;

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.

java
        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.

java
        @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