Application Code Snippet

Application Code Snippet

  • To Initialize and Get Location Manager Object:
    The application gets the location manager object using an Android existing API:
    LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE)
    Obtain the LocationManager object in order to use the API's listed below.
  • To Request Location Updates:
    To request location updates using the Zebra Locationing service as a provider:
    manager.requestLocationUpdates("rtt", 5000, 1, listener);
    By default, Android provides two providers: GPS and network providers. Zebra provides a specific FTM provider called ”rtt” provider, which can be accessed through the APIs of the Location Manager services. Android provides an API to query the list of supported providers. Application developers can use the API to retrieve the list of providers supported by the product. [getAllProviders]
    Here, the listener is Android's existing listener called LocationListener to get the location updates.
    LocationListener listener = new LocationListener()
    {
    @Override
    public void onLocationChanged(Location location) {location.getLongitude();location.getLatitude(); }
    }
  • To Remove Location Updates:
    To stop the location updates using blow API
    manager.removeUpdates(listener);
  • To Get the Last Known Location:
    To get the last known location, one should use the Android API below:
    Location loc = manager.getLastKnownLocation("rtt")
  • To Get Current Location:
    1. manager.requestSingleUpdate("rtt", listener,Looper);//use this API for A10 and below
    2. manager.getCurrentLocation("rtt",new CancellationSignal(), new CustomExecutor(),newConsumer<Location>()
    {
    @Override
    public void accept (Location location) {
    if (location != null) {
    location.getLongitude();
    location.getLatitude();
    }
    }
    }); // use this AI for Android A11 and above