小编Ann*_*kou的帖子

融合位置Api setSmallestDisplacement忽略/不工作

我正在尝试创建一个服务,每隔x秒和距离后接收位置更新.我在x秒后收到更新,但从未离开y距离.我用不同的值多次测试它,似乎setSmallestDisplacement根本不起作用.有关此事的各种帖子,但没有任何解决方案.如果有人可以帮助我,甚至指向不同的方向,我将不胜感激.

我的服务

public class GPS_Service extends Service implements GoogleApiClient.ConnectionCallbacks,
    GoogleApiClient.OnConnectionFailedListener, LocationListener {

private GoogleApiClient mGoogleApiClient;
private LocationRequest mLocationRequest;
private int timethresh;
private int distancethresh;
protected Location mCurrentLocation;

@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onCreate() {
    super.onCreate();

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
    mGoogleApiClient.connect();

}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    mLocationRequest = new LocationRequest();
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    //Set the desired interval for active location updates, in milliseconds.
    mLocationRequest.setInterval(60* 1000);
    //Explicitly …
Run Code Online (Sandbox Code Playgroud)

android google-play-services fusedlocationproviderapi android-fusedlocation

7
推荐指数
1
解决办法
4615
查看次数