简体   繁体   中英

How to prevent blue dot update in Google Map V2 Android?

I have following code:

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);
    }
}

How to prevent the blue dot does too fast update in Google Map?

It doesn't call onLocationChanged when blue dot position is changed.

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

remove setNumUpdates because it will call only once

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM