Google play services and setInterval

Asked

Viewed 86 times

0

I’m trying to use google play service to get the user’s position. The problem is, I have a dynamic time frame for sending this position to the server. However, Locationclient does not respect this range, regardless of the value it has, the position update takes place in a fixed range of 5 s.

Could someone help me?

The code:

private LocationClient locationClient;

public void iniciarBusca(long updateInterval, long fastestInterval) {
    mLocationRequest = LocationRequest.create();

    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    mLocationRequest.setInterval(updateInterval);
    mLocationRequest.setFastestInterval(fastestInterval);

    locationClient = new LocationClient(activity, this, this);      
    locationClient.connect();
}

public void disconectar() {
    try {
        locationClient.disconnect();
    } catch (Exception e) {
    }
}
  • What value are you putting to the fastestInterval?

  • Is dynamic, is the same value that is calculated for updateInterval.

  • What are the values you expect for these two fields? When you use fastestInterval, you are telling Play Services that your Location is dynamic, that is, it is calculated based on battery state, network, accuracy etc., what may be happening is that Play Services is calculating this time for you.

1 answer

1


Hello my first tip is you put the connect and the disconnect within the onPause and of onResume thus:

    @Override
    protected void onResume() {
        super.onResume();
        locationClient.connect();
    }

    @Override
    protected void onPause() {
        super.onPause();
        locationClient.disconnect();
    }

And about the interval I did not understand very well your intention because the value of updateInterval and fastestInterval is equal to zero because you did not put value to them just set them as setInterval and setFastestInterval.

Correct me if I’m wrong. A Hug.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.