我正在使用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);

关于android - 如何在调用requestLocationUpdates之后更改FusedLocationApi更新间隔,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32721475/

10-12 04:26