如何防止Google Map V2 Android中的蓝点更新?

时间:2017-04-17 05:03:58

标签: android google-maps-android-api-2

我有以下代码:

private long fasterIntervalTime = 1 * 5 * 1000;
private long intervalTime = 1 * 20 * 1000;
private LocationRequest mLocationRequest;

public boolean getLocation() {    
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    mLocationRequest.setNumUpdates(1);
    mLocationRequest.setInterval(intervalTime);
    mLocationRequest.setFastestInterval(fasterIntervalTime);
    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}

@Override
public void onLocationChanged(Location location) {
    Log.d(TAG, "Getting location : " + (location == null));
    if (mGoogleApiClient.isConnected()) {
        LocationServices.FusedLocationApi.removeLocationUpdates(
                mGoogleApiClient, this);
    }
}

如何防止蓝点在Google Map中更新太快?

当蓝点位置发生变化时,它不会调用onLocationChanged

1 个答案:

答案 0 :(得分:0)

//stop location updates
if (mGoogleApiClient != null) {
    LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
}

删除setNumUpdates,因为它只会调用一次