我使用FusedLocationApi获取当前位置。它的工作正常,但有时它不在隧道中工作。在隧道中获得错误的位置纬度和经度。我计算当前位置和最后位置之间的距离以及在隧道中超过100公里的距离。意味着隧道FusedLocationApi完全不起作用。
private static final long INTERVAL = 5 * 1000;
private static final long FASTEST_INTERVAL = 5 * 1000;
private static final int SMALLEST_DISPLACEMENT = 5;
public LocationRequest mLocationRequest;
public GoogleApiClient mGoogleApiClient;
@Override
public void onCreate() {
super.onCreate();
//location service
createLocationRequest();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Places.PLACE_DETECTION_API)
.addApi(LocationServices.API)
.addApi(Places.GEO_DATA_API)
.addConnectionCallbacks(this).build();
}
protected void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(INTERVAL);
mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
mLocationRequest.setSmallestDisplacement(SMALLEST_DISPLACEMENT);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
public void startLocationUpdates() {
PendingResult<Status> pendingResult = LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
Log.d("TAG", "Location update started ..............: ");
}