Skip to content

quic-nwtn/tps-location-quick-start-android

 
 

Repository files navigation

TPS Location SDK: Quick Start for Android

Platform

The Quick Start project illustrates minimal steps to integrate the SDK into your app.

Contact TPS

Contact [email protected] to request access to the SDK and get the API key.

Add SDK to your project

Put the SDK library file under the app/libs/ subdirectory and add it to the dependencies section of your build.gradle:

dependencies {
    implementation files('libs/wpsapi.aar')
}

Import the SDK

Import the Skyhook WPS package:

import com.skyhookwireless.wps;

Initialize API

Create a new instance of the XPS class in the onCreate method of your activity or application class and set your API key:

private IWPS xps;
...
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    xps = new XPS(this);
    xps.setKey("YOUR KEY");
    ...
}

Make sure to replace "YOUR KEY" with your real API key in the Quick Start app source code (see the onCreate() method in MainActivity.java).

Request location permission

In order to be able to start location determination, your app must first obtain the ACCESS_FINE_LOCATION permission from the user:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    ActivityCompat.requestPermissions(
        this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, 0);
}

Request location

Once the location permission has been granted, you can make a locaton request.

Note that the callback methods are invoked from the background thread, so you have to use runOnUiThread() to manipulate the UI.

xps.getLocation(null, WPSStreetAddressLookup.WPS_NO_STREET_ADDRESS_LOOKUP, false, new WPSLocationCallback() {
    @Override
    public void handleWPSLocation(WPSLocation location) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                // display location
            }
        });
    }

    @Override
    public WPSContinuation handleError(WPSReturnCode error) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                // display error
            }
        });

        return WPSContinuation.WPS_CONTINUE;
    }

    @Override
    public void done() {
        // after done() returns, you can make more XPS calls
    }
});

Note: starting with Android 9 a fresh Wi-Fi location can only be calculated four times during a 2-minute period.

Further Read

Please refer to the full SDK guide for more information.

License

License

Copyright (c) 2023 Qualcomm Innovation Center, Inc. All Rights Reserved.

This work is licensed under the CC BY-ND 4.0 License. See LICENSE for more details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%