6

x秒ごとにy距離後に位置更新を受信するサービスを作成しようとしています。私はx秒後に更新を受けますが、y距離後は更新しません。私はそれを複数の異なる値でテストし、setSmallestDisplacementはまったく動作していないようです。その問題については様々な記事がありましたが、解決策はありませんでした。もし誰かが私を助けたり、私を別の方向に向けることができたら、私はそれを感謝します。融合した場所Api 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 set the fastest interval for location updates, in milliseconds. 
    mLocationRequest.setFastestInterval(30* 1000); 
    //Set the minimum displacement between location updates in meters 
    mLocationRequest.setSmallestDisplacement(1); // float 


    return super.onStartCommand(intent, flags, startId); 

} 

@Override 
public void onConnected(Bundle bundle) { 
    if (mCurrentLocation == null) { 
     mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); 

    } 
    //Requests location updates from the FusedLocationApi.  
    startLocationUpdates(); 

} 

@Override 
public void onLocationChanged(Location location) { 
    mCurrentLocation = location; 
    //Toast.makeText(this, ""+mCurrentLocation.getLatitude()+","+mCurrentLocation.getLongitude(), Toast.LENGTH_SHORT).show(); 
    System.out.println(""+mCurrentLocation.getLatitude()+","+mCurrentLocation.getLongitude()); 


} 

@Override 
public void onConnectionSuspended(int i) { 
    // The connection to Google Play services was lost for some reason. We call connect() to 
    // attempt to re-establish the connection. 
    mGoogleApiClient.connect(); 
} 


@Override 
public void onConnectionFailed(ConnectionResult connectionResult) { 
    Toast.makeText(getApplicationContext(),"Location services connection failed with code " + connectionResult.getErrorCode(), Toast.LENGTH_LONG).show(); 

} 

protected void startLocationUpdates() { 
    LocationServices.FusedLocationApi.requestLocationUpdates(
      mGoogleApiClient, mLocationRequest, this); 

} 

}

答えて

4

CGRのこのSO question特に答えによります。

LocationRequestに設定されている変位は、デバイスが依然として変位している場合に位置を取得する機会はありません。置き換えが自然(間隔と高速の侵入)より優先されます。私が推測できるように - LocationServices.FusedLocationApi.requestLocationUpdates()に別のLocationRequestオブジェクト(変位が設定されていない)を渡した可能性があります。

なLocationRequest setSmallestDisplacement( smallestDisplacementMetersフロート)

はメートル単位で位置更新の間の最小容量を設定されています。デフォルトでは、この値は0です。同じオブジェクトを返します。これにより、セッターを連鎖させることができます。

注:ACCESS_COARSE_LOCATION なくACCESS_FINE_LOCATION持つアプリケーションからロケーション要求は自動的 遅い間隔に絞らされ、精度の粗いレベルを示す位置オブジェクトのみ に難読化されるであろう。

詳細については、pageをご確認ください。

2

このような何か試してみてください:

protected void createLocationRequest() { 
    mLocationRequest = new LocationRequest(); 

    mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS); 

    mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS); 

    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); 

    mLocationRequest.setSmallestDisplacement(100); //100 meters 
} 
関連する問題