How to integrate our Indoor Location SDK

6

These few lines will help you to integrate our indoor location SDK in your application.

For it, you just have to follow these three steps:

  1. Preparing the environment for the SDK
  2. Initializing the indoor location provider
  3. Retrieving indoor maps

Preparing the environment for the SDK

AndroidManifest.xml

The minimum SDK version that the app should be API 18

<!– Bluetooth –>

<uses-permission android:name=”android.permission.BLUETOOTH” />

<uses-permission android:name=”android.permission.BLUETOOTH_ADMIN” />

<!– GPS –>

<uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION”/>

<uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION” />

We have to ensure that the device is capable to use Bluetooth Low Energy…

These few lines will help you to integrate our indoor location SDK in your application.

For it, you just have to follow these three steps:

  1. Preparing the environment for the SDK
  2. Initializing the indoor location provider
  3. Retrieving indoor maps

Preparing the environment for the SDK

AndroidManifest.xml

The minimum SDK version that the app should be API 18

<!– Bluetooth –>

<uses-permission android:name=”android.permission.BLUETOOTH” />

<uses-permission android:name=”android.permission.BLUETOOTH_ADMIN” />

<!– GPS –>

<uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION”/>

<uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION” />

We have to ensure that the device is capable to use Bluetooth Low Energy.

(Bluetooth 4.0), hence the following feature shall be included

<uses-feature

android:name=”android.hardware.bluetooth_le”

android:required=”true” />

Finally we need to define the Indoor Service to be used. Through this service the indoor location position will be provided to the app.

<application…

<service

android:name=”com.oym.indoor.location.IndoorLocationService”

android:exported=”false” />

Importing libraries

In order to work properly, the app shall include the following libraries:

  • indoor-1.0.0.jar
  • oym-links-sdk.1.4.1.jar
  • httpclientandroidlib-1.1.2.jar
  • jackson -core-asl-1.9.12.jar
  • jackson -jaxrs-1.9.12.jar
  • jackson -mapper-asl-1.9.12.jar
  • jackson-xc-1.9.12.jar

The app shall include the Google Play Services in order to be able to use the Google Location Services API.

Initializing the indoor location provider

After making all the modifications mentioned in the previous section, it is necessary to bear in mind that the application is using the Google Services API, Bluetooth and WiFi/Network connection, hence it is necessary to check that all this features are available.

The next step is to define an IndoorLocationBroadcast to handle the computed position. This IndoorLocationBroadcast will be called each time a position is computed.

private IndoorLocationBroadcast broadcast = new IndoorLocationBroadcast() {

@Override

public void onReceive(IndoorLocation location) {

// TODO Auto-generated method stub

}

};

The IndoorLocation object includes all the required information to locate the user: latitude, longitude, number of iBeacons used, accuracy, floor number, building name and the positioning type.

The following step is to create a new instance of the indoor location library:

IndoorLocationLib lib = new IndoorLocationLib(context, oymWebservicesUrl, oymUser, oymPassword);

The final step to start the library is provide the IndoorLocationBroadcast to the library. We also provide a StartLocateCallback that will handle the start of the service and provide feedback whether the action was successful or not to the developer. To do that we use the startLocate() method, where the input is the IndoorLocationBroadcast, the StartLocateCallback and the third optional parameter is the update rate in milliseconds. If the update rate is not specified, the value by default is 2 seconds.

lib.startLocate(br, startCallback 2000);

After starting the library, the IndoorBroadcastReceiver will be used when a new position is computed.

Stopping the library

In order to stop properly the library, it is necessary to call the stopLocate() method when the library is no longer needed and the location service should be stopped

lib.stopLocate();

Retrieving indoor maps

In order to show the indoor maps overlap in Google Map, we assume that the app already have an initialized GoogleMap object called map. Further information in how to include a map in your app can be found at https://developers.google.com/maps/documentation/android/

The first step is to retrieve the buildings from the server. In order to do that we use the Indoor class, inside com.oym.indoor package. The following constructor shall be used. In there the webservices Url, username and password shall be provided. The method already handles the connection to the server, hence a ConnectCallback shall be used as input parameter.

Indoor indoor = new Indoor(oymWebservicesUrl, user, password, callback)

When the connection is established successfully, the next step is to retrieve the buildings from the server. For that, with the Indoor object we created, we use the getBuildings() methods. There are simplified versions reducing input parameters of this method, which might apply for certain cases.

public void getBuildings(List<String> buildingIdList, String boundingBox, int offset, int bucketSize, GetBuildingsCallback callback)

In there we specify a list of buildingId to be retrieved, the bounding box in which the search shall be performed, an offset for the results and the max size of the result. As well, we need to provide a GetBuildingsCallback to check whether the operation has been successful.

When the building list has been successfully retrieved, all the information needed is already retrieved. In each Building object, it includes all the floors available for that building, including their tile providers. In order to access an UrlTileProvider we just need to call the getTileProvider() method in a Floor object:

ArrayList<Floor> floors = buildings.get(iBuilding).getFloorsList();

UrlTileProvider tiles = floors.get(iFloor).getTileProvider();

Finally, this UrlTileProvider can be directly added to the map.

map.addTileOverlay(new TileOverlayOptions().tileProvider(tiles));

Exiting the app

Before exiting the app it is advisable to disconnect from the server. For that, the disconnect() method shall be called.

indoor.disconnect();

Find more information about our indoor location SDK on our Dev Zone.

Leave a Reply