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 5 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.mapping:provider-senion:3.0.0
Senion Lab BLE location provider
MSE
com.phunware.mapping:provider-mse:3.0.0
Cisco MSE location provider
GPS
com.phunware.mapping: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.0.0'
    compile 'com.phunware.mapping:provider-senion:3.0.0'
    ...
}

Step 2 - Set the Location Provider on the PhunwareMapManager

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
 
    ...
 
	mapManager.setLocationProviderFactory(SenionProviderFactory.create(this,
    	    getString(R.string.pw_sl_customer_id),
        		getString(R.string.pw_sl_map_id)));

	...
}

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.

 

Step 3 - 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) {
				...

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

				...
            }

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

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

 

Step 4 - 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