如何在调用requestLocationUpdates后更改FusedLocationApi更新间隔

Pie*_*ult 7 android google-play-services fusedlocationproviderapi

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

mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(30000);
LocationServices.FusedLocationApi.requestLocationUpdates(
            mGoogleApiClient, mLocationRequest, this);
Run Code Online (Sandbox Code Playgroud)

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

mik*_*ean 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);
Run Code Online (Sandbox Code Playgroud)