【问题标题】:Fused Location Provider doesnot give Location Updates on DisplacementFused Location Provider 不会在位移时提供位置更新
【发布时间】:2015-11-25 03:58:28
【问题描述】:

我使用 Fused Location API 来获取位置更新。我在根据 setTimeInterval 设置 LocationRequest 时收到更新。但我只需要更新 10m 运动。所以我放了 setSmallestDisplacement(10) 。但是当我放 setSmallestDisplacement(10) 时,我没有得到更新。以下是我的 LocationUpdate 类

public class LocationManger implements
    GoogleApiClient.ConnectionCallbacks,
    GoogleApiClient.OnConnectionFailedListener, com.google.android.gms.location.LocationListener {

GoogleApiClient mLocationClient;
Location mCurrentLocation;
LocationRequest mLocationRequest;
Context mContext;


public LocationManger(Context context) {
    super();
    mLocationClient = new GoogleApiClient.Builder(context)
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
    mContext = context;
}


@Override
public void onLocationChanged(Location location) {
    mCurrentLocation = location;

}


@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    Helper.showToast("failed", mContext);

}

@Override
public void onConnected(Bundle arg0) {

if (mLocationRequest == null) {
        mLocationRequest = LocationRequest.create();
         mLocationRequest.setSmallestDisplacement(10);
        mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    }

    LocationServices.FusedLocationApi.requestLocationUpdates(mLocationClient, mLocationRequest, this);

}

@Override
public void onConnectionSuspended(int i) {
    mLocationClient.connect();

}

/**
 * Function to start the location updates
 */
public void startLocationUpdates() {
    if (!mLocationClient.isConnected())
        mLocationClient.connect();
}

/**
 * function to stop the location updates
 */
public void stopUpdatingLocation() {
    if (mLocationClient.isConnected()) {

     LocationServices.FusedLocationApi.removeLocationUpdates(mLocationClient, this);
    }
    mLocationClient.disconnect();

}

/**
 * function to get the current latitude
 */
public double getCurrentLatitude() {
    if (mCurrentLocation != null) {
        return mCurrentLocation.getLatitude();
    }
    return 0;

}

/**
 * function to get the current longitude
 */
public double getCurrentLongitude() {
    if (mCurrentLocation != null) {
        return mCurrentLocation.getLongitude();
    }
    return 0;
}

/**
 * function to get the current location
 */
public Location getCurrentLocation() {
    return LocationServices.FusedLocationApi.getLastLocation(mLocationClient);
}

}

如果有人知道这个问题,请给我一个解决方案。提前致谢

【问题讨论】:

  • 它是否在时间间隔内工作
  • 是的,它在时间间隔内工作正常
  • 尝试将时间间隔设为0并加载它
  • 是的...我试过了。但我不需要时间间隔只需要位移
  • 您手机的 GPS 设置是什么?是高精度还是省电?

标签: android gps android-fusedlocation


【解决方案1】:

使用 setFastestInterval(0) 允许比 setInterval 更频繁地更新。否则你会错过一些位移更新

【讨论】:

  • 它是否可以在没有时间间隔的情况下工作。我不需要基于时间间隔的更新
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-17
  • 1970-01-01
  • 1970-01-01
  • 2018-06-02
  • 1970-01-01
  • 1970-01-01
  • 2016-06-20
相关资源
最近更新 更多