Code Examples

Please read following section, if you are using java for developing.

Please include implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" to your build.gradle

And make sure you are enabled Java 8 language features by add following to build.gradle

android {
    ...
    // Configure only for each module that uses Java 8
    // language features (either in its source code or
    // through dependencies).
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

Setting up api key or secret

Kotlin
// set your api key and api secret. 
IAGSManager.getInstance(this).setApiKey("SET YOUR API KEY HERE", "SET YOUR SECRET KEY HERE")
Java
// set your api key and api secret. 
IAGSManager.Companion.getInstance(this).setApiKey("SET YOUR API KEY HERE", "SET YOUR SECRET KEY HERE");

Alternative, you can add api key IAGSApiKey and api secret IAGSSecretKey to metadata in your application manifests.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.indooratlas.groundsage.sdk.example">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity>
        ...
        </activity>

        <meta-data android:name="IAGSApiKey" android:value="SET YOUR API KEY HERE"/>
        <meta-data android:name="IAGSSecretKey" android:value="SET YOUR SECRET KEY HERE"/>
    </application>
</manifest>

Request venue information

Kotlin
class MainActivity : AppCompatActivity(), IAGSManagerListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        requestVenueDensityExample()
    }
    
    fun requestVenueInformationExample() {
        val sdk = IAGSManager.getInstance(this)
        // set your api key and api secret.
        sdk.setApiKey(
            "SET YOUR API KEY HERE",
            "YOUR SECRET KEY HERE"
        )
        // start to request venue information
        sdk.requestVenueInfo { venues, _ ->
            print(venues)
        }
    }
}
Java
public class MainActivity extends AppCompatActivity implements IAGSManagerListener {
    private final String TAG = MainActivity.class.getSimpleName();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        requestVenueInformationExample();
    }
    
    void requestVenueInformationExample() {
        IAGSManager sdk = IAGSManager.Companion.getInstance(this);
        // set your api key and api secret.
        sdk.setApiKey(
            "SET YOUR API KEY HERE",
            "YOUR SECRET KEY HERE"
        );
        // start to request venue information
        sdk.requestVenueInfo((iagsVenues, e) -> {
            Log.d(TAG, String.format("%s, %s", iagsVenues, e));
            
            return Unit.INSTANCE;
        });
    }
}

Register a callback and subscription

Kotlin
class MainActivity : AppCompatActivity(), IAGSManagerListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        subscriptionVenueDensityExample()
    }
    
    fun subscriptionVenueDensityExample() {
        val sdk = IAGSManager.getInstance(this)
        // set your api key and api secret.
        sdk.setApiKey(
            "SET YOUR API KEY HERE",
            "YOUR SECRET KEY HERE"
        )
        sdk.addGroundSageListener(this)
        // start subscription to request venue density
        sdk.startSubscription()
    } 

    override fun onUpdateDensity(venueDensity: IAGSVenueDensity?) {
        println(String.format("update density = %s", venueDensity))
    }

    override fun onEnterDensityRegion(region: IARegion) {
        println(String.format("Enter region = %s", region))
    }

    override fun onExitDensityRegion(region: IARegion) {
        println(String.format("Exit region = %s", region))
    }
}
Java
public class MainActivity extends AppCompatActivity implements IAGSManagerListener {
    private final String TAG = MainActivity.class.getSimpleName();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        subscriptionVenueDensityExample();
    }

    void subscriptionVenueDensityExample() {
        IAGSManager sdk = IAGSManager.Companion.getInstance(this);
        // set your api key and api secret.
        sdk.setApiKey(
            "SET YOUR API KEY HERE",
            "YOUR SECRET KEY HERE"
        );
        // start subscription to request venue density
        sdk.startSubscription();
    }

    @Override
    public void onUpdateDensity(@Nullable IAGSVenueDensity venueDensity) {
        Log.d(TAG, String.format("Update density = %s", venueDensity));
    }

    @Override
    public void onEnterDensityRegion(@NotNull IARegion region) {
        Log.d(TAG, String.format("Enter region = %s", region));
    }

    @Override
    public void onExitDensityRegion(@NotNull IARegion region) {
        Log.d(TAG, String.format("Exit region = %s", region));
    }
}

Remove GroundSage listener

Kotlin
// unregister delegate for subscription callback
IAGSManager.getInstance(this).removeGroundSageListener(this)
Java
// unregister delegate for subscription callback
IAGSManager.Companion.getInstance(this).removeGroundSageListener(this);

Stop subscription

Kotlin
IAGSManager.getInstance(this).stopSubscription()
Java
IAGSManager.Companion.getInstance(this).stopSubscription();

Start location and region update examples

Kotlin
private val mIALocationListener: IALocationListener = object : IALocationListener {
    override fun onLocationChanged(iaLocation: IALocation) {}
    override fun onStatusChanged(provider: String, status: Int, extras: Bundle) {}
}
private val mRegionListener: IARegion.Listener = object : IARegion.Listener {
    override fun onEnterRegion(iaRegion: IARegion) {}
    override fun onExitRegion(iaRegion: IARegion) {}
}

fun startLocationAndRegionUpdateExample() {
    val mgr = IAGSManager.getInstance(this)
    // start receiving location updates & monitor region changes
    mgr.registerLocationListener(mIALocationListener)
    mgr.registerRegionListener(mRegionListener)
    mgr.startSubscription()
}
Java
private IALocationListener mIALocationListener = new IALocationListener() {
    @Override
    public void onLocationChanged(IALocation iaLocation) {

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {

    }
};

private IARegion.Listener mRegionListener = new IARegion.Listener() {
    @Override
    public void onEnterRegion(IARegion iaRegion) {

    }

    @Override
    public void onExitRegion(IARegion iaRegion) {

    }
};

public void startLocationAndRegionUpdateExample() {
    IAGSManager mgr = IAGSManager.Companion.getInstance(this);
    // start receiving location updates & monitor region changes
    mgr.registerLocationListener(mIALocationListener);
    mgr.registerRegionListener(mRegionListener);
    mgr.startSubscription();
}

Start/stop wayfinding example

Kotlin
private lateinit var iaWayfindingRequest: IAWayfindingRequest
private val iaWayfindingListener:IAWayfindingListener = object : IAWayfindingListener {
    override fun onWayfindingUpdate(route: IARoute?) {
        TODO("Not yet implemented")
    }
}

/**
 * Start wayfinding example
 */
fun startWayfindingExample() {
    val mgr = IAGSManager.getInstance(this)
    iaWayfindingRequest = IAWayfindingRequest.Builder()
        .withFloor(floor)
        .withLatitude(latitude)
        .withLongitude(longitude)
        .build()
    mgr.requestWayfindingUpdates(iaWayfindingRequest, iaWayfindingListener)
}

/**
 * Stop wayfinding example
 */
fun stopWayfindingExample() {
    val mgr = IAGSManager.getInstance(this)
    mgr.removeWayfindingUpdates()
}
Java
private IAWayfindingRequest mWayfindingDestination;
private IAWayfindingListener mWayfindingListener = new IAWayfindingListener() {
    @Override
    public void onWayfindingUpdate(IARoute route) {

    }
};

/**
 * Start wayfinding example
 */
public void startWayfindingExample() {
    IAGSManager mgr = IAGSManager.Companion.getInstance(this);
    mWayfindingDestination = new IAWayfindingRequest.Builder()
            .withFloor(floor)
            .withLatitude(latitude)
            .withLongitude(longitude)
            .build();
    mgr.requestWayfindingUpdates(mWayfindingDestination, mWayfindingListener);
}

/**
 * Stop wayfinding example
 */
public void stopWayfindingExample() {
    IAGSManager mgr = IAGSManager.Companion.getInstance(this);
    mgr.removeWayfindingUpdates();
}

Add/Remove geofence example

Kotlin
companion object {
    /* used to decide when bitmap should be downscaled */
    private const val MAX_DIMENSION = 2048
    private const val GEOFENCE_RADIUS_METERS = 5.0
    private var mRunningGeofenceId = 0
}
private var mIAGeofenceRequest: IAGeofenceRequest? = null
private val mIAGeofenceListener: IAGeofenceListener = object: IAGeofenceListener {
    override fun onGeofencesTriggered(p0: IAGeofenceEvent?) {
        TODO("Not yet implemented")
    }
}

/**
 * Geofences example
 */
fun addGeofencesExample(latitude: Double, longitude: Double) {
    // Add a circular geofence by adding points with a 5 m radius clockwise
    val radius = GEOFENCE_RADIUS_METERS
    val edgeCount = 12
    val EARTH_RADIUS_METERS = 6.371e6
    val latPerMeter = 1.0 / (EARTH_RADIUS_METERS * Math.PI / 180)
    val lonPerMeter = latPerMeter / Math.cos(Math.PI / 180.0 * latitude)
    val edges = ArrayList<DoubleArray>()
    for (i in 0 until edgeCount) {
        val angle = -2 * Math.PI * i / edgeCount
        val lat = latitude + radius * latPerMeter * Math.sin(angle)
        val lon = longitude + radius * lonPerMeter * Math.cos(angle)
        edges.add(doubleArrayOf(lat, lon))
    }
    val geofenceId = "My geofence " + mRunningGeofenceId++
    Log.d(TAG, "Creating a geofence with id \"$geofenceId\"")
    val geofence = IAGeofence.Builder()
        .withEdges(edges)
        .withId(geofenceId)
        .withName(geofenceId)
        .build()
    Log.i(TAG, "New geofence registered: $geofence")
    val mgr = IAGSManager.getInstance(this)
    mgr.addGeofences(
        IAGeofenceRequest.Builder()
            .withCloudGeofences(true) // listen also geofences defined in app.indooratlas.com
            .withGeofence(geofence)
            .build().also { mIAGeofenceRequest = it }, mIAGeofenceListener
    )
}

/**
 * Remove geofences example
 */
fun removeGeofencesExample() {
    val mgr = IAGSManager.getInstance(this)
    mgr.removeGeofenceUpdates(mIAGeofenceListener)
}
Java
private static final String TAG = IALocationManagerMigrationJava.class.getSimpleName();

/* used to decide when bitmap should be downscaled */
private static final int MAX_DIMENSION = 2048;

private static final double GEOFENCE_RADIUS_METERS = 5.0;

private static int mRunningGeofenceId = 0;
private IAGeofenceRequest mIAGeofenceRequest;
private IAGeofenceListener mIAGeofenceListener = new IAGeofenceListener() {

    @Override
    public void onGeofencesTriggered(IAGeofenceEvent iaGeofenceEvent) {

    }
};

/**
 * Geofences example
 */
public void addGeofencesExample(double latitude, double longitude) {
    // Add a circular geofence by adding points with a 5 m radius clockwise
    final double radius = GEOFENCE_RADIUS_METERS;
    final int edgeCount = 12;
    final double EARTH_RADIUS_METERS = 6.371e6;
    final double latPerMeter = 1.0 / (EARTH_RADIUS_METERS * Math.PI / 180);
    final double lonPerMeter = latPerMeter / Math.cos(Math.PI / 180.0 * latitude);

    ArrayList<double[]> edges = new ArrayList<>();
    for (int i = 0; i < edgeCount; i++) {
        double angle = -2 * Math.PI * i / edgeCount;
        double lat = latitude + radius * latPerMeter * Math.sin(angle);
        double lon = longitude + radius * lonPerMeter * Math.cos(angle);
        edges.add(new double[]{lat, lon});
    }

    String geofenceId = "My geofence " + mRunningGeofenceId++;
    Log.d(TAG, "Creating a geofence with id \"" + geofenceId + "\"");
    IAGeofence geofence = new IAGeofence.Builder()
            .withEdges(edges)
            .withId(geofenceId)
            .withName(geofenceId)
            .build();


    Log.i(TAG, "New geofence registered: " + geofence);
    IAGSManager mgr = IAGSManager.Companion.getInstance(this);
    mgr.addGeofences(mIAGeofenceRequest = new IAGeofenceRequest.Builder()
            .withCloudGeofences(true) // listen also geofences defined in app.indooratlas.com
            .withGeofence(geofence)
            .build(), mIAGeofenceListener);

}

/**
 * Remove geofences example
 */
public void removeGeofencesExample() {
    IAGSManager mgr = IAGSManager.Companion.getInstance(this);
    mgr.removeGeofenceUpdates(mIAGeofenceListener);
}

Stop subscription

Kotlin
/**
 * Register orientation listener
 */
fun registerOrientationListener() {
    val mgr = IAGSManager.getInstance(this)
    mgr.registerOrientationListener(IAOrientationRequest(1.0, 0.0), mIAOrientationListener)
}

/**
 * Unregister orientation listener
 */
fun unregisterOrientationListener() {
    val mgr = IAGSManager.getInstance(this)
    mgr.unregisterOrientationListener(mIAOrientationListener)
}
Java
/**
 * Register orientation listener
 */
public void registerOrientationListener() {
    IAGSManager mgr = IAGSManager.Companion.getInstance(this);
    mgr.registerOrientationListener(new IAOrientationRequest(1, 0), mIAOrientationListener);
}

/**
 * Unregister orientation listener
 */
public void unregisterOrientationListener() {
    IAGSManager mgr = IAGSManager.Companion.getInstance(this);
    mgr.unregisterOrientationListener(mIAOrientationListener);
}

For more exmaples, please refer to SDK examples TODO: above link should be GroundSage SDK examples