如何在调用 requestLocationUpdates 后更改 FusedLocationApi 更新间隔
How to change FusedLocationApi update interval after requestLocationUpdates has been called
我正在使用 LocationServices.FusedLocationApi 以给定的时间间隔获取位置更新,这是在传递给 requestLocationUpdates 的 LocationRequest 对象上设置的:
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(30000);
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
我需要更改侦听器开始接收位置更新后的间隔值。正确的做法是什么?
//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);
我正在使用 LocationServices.FusedLocationApi 以给定的时间间隔获取位置更新,这是在传递给 requestLocationUpdates 的 LocationRequest 对象上设置的:
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(30000);
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
我需要更改侦听器开始接收位置更新后的间隔值。正确的做法是什么?
//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);