7

我正在使用 LocationServices.FusedLocationApi 以给定的时间间隔获取位置更新,该时间间隔是在传递给 requestLocationUpdates 的 LocationRequest 对象上设置的:

mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(30000);
LocationServices.FusedLocationApi.requestLocationUpdates(
            mGoogleApiClient, mLocationRequest, this);

在侦听器开始接收位置更新后,我需要更改间隔的值。这样做的正确方法是什么?

4

1 回答 1

6
    //remove location updates so that it resets
    LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);

    //change the time of location updates
    mLocationRequest = LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(TIME_INTERVAL)
            .setFastestInterval(TIME_INTERVAL_MIN);

    //restart location updates with the new interval
    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
于 2016-03-15T18:51:38.220 回答