Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

In order to show the user's current location,  we will need to add a Location Provider to provide updated location information.

Here's a brief summary of the location providers Phunware provides:

ProviderCompile StatementDescription
BLE
com.phunware.location:provider-senion:3.0.0
Senion Lab BLE location provider
MSE
com.phunware.location:provider-cmx:3.0.0
Cisco MSE location provider
GPS
com.phunware.location:provider-gps:3.0.0
GPS location provider

 

Below are the steps for integrating a BLE Location Provider with your app.

Step 1 - Add a location provider as a compile dependency.

apply plugin: 'com.android.application' 
android {
    ...
}
 
dependencies {
    ...
    compile 'com.phunware.mapping:mapping:3.1.0'
    compile 'com.phunware.location:provider-senion:3.1.0'
    ...
}


Step 2 - Set the Location Provider and Enable Location Updates

@Override    
public void onPhunwareMapReady(PhunwareMap phunwareMap) {
	mapManager.setPhunwareMap(map);
	mapManager.addBuilding(getResources().getInteger(R.integer.building_id),
        new Callback<Building>() {
            @Override
            public void onSuccess(final Building building) {
				...

                mapManager.setLocationProvider(SenionProviderFactory.create(this,
                        getString(R.string.sl_customer_id),
                        getString(R.string.sl_map_id),
                        getSenionFloorMap()).createLocationProvider(), building);



                // enable my location (blue dot)
                mapManager.setMyLocationEnabled(true);

				...
            }

            @Override
            public void onFailure(Throwable e) {
            }
        });
}

This step tells the PhunwareMapManager what provider will be used to get location updates.  In this case,  the Senion Location Provider requires a customer id and map id.  The method getSenionFloorMap() returns a HashMap of Senion floor ids to MaaS floor ids.

Once the PhunwareMap and the Building are loaded,  we'll enable location updates.

 

Step 3 - Manage Location Updates when in the Background

@Override
protected void onPause() {
    super.onPause();
    if (mapManager != null) {
        mapManager.setMyLocationEnabled(false);
    }
}

@Override
protected void onResume() {
    super.onResume();

    if (mapManager != null) {
        mapManager.setMyLocationEnabled(true);
    }
}

Constant location updates when in the background will drain a battery.  In order to prevent this, we intercept activity lifecycle methods to disable and enable location updates.

 

 

 

  • No labels