Coder Social home page Coder Social logo

tps-location-quick-start-android's Introduction

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.

tps-location-quick-start-android's People

Contributors

quic-sgalat avatar quic-nwtn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.