Skip to end of metadata
Go to start of metadata

This documentation is no longer actively supported and may be out of date. Going forward, please visit and bookmark our new site (https://docs.phunware.com/) for up-to-date documentation.

Getting Started (Android)

 

This guide is a quick start to adding a Phunware Map to an Android app.  Android Studio is the recommended development environment for building an app with the Phunware Mapping SDK.

Step 1- Add the Phunware Maven remote repository.

Insert this block into allprojects -> repositories:

allprojects {
    repositories {
 
		maven {
    		url "https://nexus.phunware.com/content/groups/public/"
		}
    }
}

 

Step 2 - Add the Mapping SDK as a dependency in your app's build.gradle file

This one line includes all dependencies necessary to use the Phunware Mapping SDK.

apply plugin: 'com.android.application'

android {
	...
}

dependencies {
	...
    compile 'com.phunware.mapping:mapping:3.1.2'
    ...
}

 

Step 3 - Add your Google Maps Api Key to AndroidManifest.xml

Create a string resource that contains your Google Maps API Key.  

If you need help getting a Google Maps API Key,  please find instructions here: Get a Google Maps API key

<meta-data android:name="com.google.android.geo.API_KEY" 
           android:value="@string/google_maps_api_key"/>

 

Step 4 - Add Phunware keys for App Id, Access Key, Signature Key and Encryption Key

Your App Id, Access Key, Signature Key and Encryption Key are found on the MaaS portal on the Applications tab. 

See: Config Guides (Core)

<meta-data android:name="com.phunware.APPLICATION_ID" android:value="@string/app_id" />
<meta-data android:name="com.phunware.ACCESS_KEY" android:value="@string/access_key" />
<meta-data android:name="com.phunware.SIGNATURE_KEY" android:value="@string/signature_key" />
<meta-data android:name="com.phunware.ENCRYPTION_KEY" android:value="@string/encrypt_key" />

 

Step 5 - Add MapFragment to your layout

This is where the Phunware Mapping SDK will render the map.  

NOTE: the fragment will be found via the R.id.map id.

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:name="com.phunware.mapping.MapFragment"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

 

Step 6 - Get the Map asynchronously in your activity:

The PhunwareMapManager is created and the Phunware API keys are registered in this step.

Then the MapFragment is located and the map is loaded asynchronously.  

Your implementation of OnPhunwareMapReadyCallback will be called when the map is ready.

	private PhunwareMapManager mapManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

		...

        mapManager = PhunwareMapManager.create(this);

        // register the Phunware API keys
        PwCoreSession.getInstance().registerKeys(this);

        MapFragment mapFragment = (MapFragment) getFragmentManager()
                .findFragmentById(R.id.map);
        if (mapFragment != null) {
            mapFragment.getPhunwareMapAsync(this);
        }
    }

 

 

Step 7 - Make sure your activity implements OnPhunwareMapReadyCallback

Once the PhunwareMap is ready, set it in the PhunwareMapManager and add a building by id.

Building additions are also asynchronous,  so a callback will notify you of success or failure.

public class MainActivity extends AppCompatActivity implements OnPhunwareMapReadyCallback {

	...
	
    @Override
    public void onPhunwareMapReady(PhunwareMap phunwareMap) {
        mapManager.setPhunwareMap(phunwareMap);

        mapManager.addBuilding(getResources().getInteger(R.integer.building_id),
                new Callback<Building>() {
            @Override
            public void onSuccess(Building building) {
            }

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

 

 

Step 8 - Do something interesting with the Building

Once the map and building are loaded, move and zoom the view so you can see the initial floor.

public class MainActivity extends AppCompatActivity implements OnPhunwareMapReadyCallback {
    @Override
    public void onPhunwareMapReady(final PhunwareMap phunwareMap) {
        mapManager.setPhunwareMap(phunwareMap);

        mapManager.addBuilding(getResources().getInteger(R.integer.building_id),
                new Callback<Building>() {
            @Override
            public void onSuccess(Building building) {
                FloorOptions initialFloor = building.initialFloor();
                building.selectFloor(initialFloor.getLevel());
                // animate the camera to the building at an appropriate zoom level
                // so we can see the building
                CameraUpdate cameraUpdate = CameraUpdateFactory
                        .newLatLngBounds(initialFloor.getBounds(), 4);
                phunwareMap.getGoogleMap().animateCamera(cameraUpdate);
            }
            @Override
            public void onFailure(Throwable throwable) {
            }
        });        
    }
  • No labels