Skip to content

Instantly share code, notes, and snippets.

@ndurell
Last active May 23, 2016
Embed
What would you like to do?
Gist detail how we use Fused Location Provid

Build google api client:

m_googleApiClient = builder.
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .addApi(LocationServices.API)
        .build();

The location request looks like this:

LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
locationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);

When connected

    @Override
    public void onConnected(Bundle bundle) {
      m_fusedLocationProviderApi.requestLocationUpdates(m_googleApiClient, m_locationRequest, this);
    }

We listen for callbacks:

    @Override
    public void onLocationChanged(Location location) {
      m_lastUpdate = DateTime.now()
      m_location = location;
    }

We find that occaisionally onLocationChanged stops getting called. We track this by periodically checking if the m_lastUpdate value has been updated. We also listen for failure callbacks but we almost never see those being called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment