Android 7.1.2でNexus 6pを使用しています。私は、デバイスの位置精度をHIGH_ACCURACY
に設定しました。 私のコードでは、FusedLocation
APIを使用して、ロケーション更新のバックグラウンドサービスを持っています。ご覧のとおり、ロケーションリクエストの優先度をHIGH_ACCURACY
に設定しました。 これは、デバイスが机の上に何も動かさなくてもテストしました。ほとんどの場合、同じLAT/LONG値が得られましたが、デバイスによってはLAT /動いていなかった。 getAccuracy
メソッドを使用して位置精度を印刷しました。 getAccuracy
メソッドが値> = 68を返すと、デバイス(ユーザー)がこの場所にいる可能性が高いことを意味します。 したがって、このメソッド(別のバージョンのコード)を使用して、getAccuracyが値> = 68を返しているかどうかを確認してから、場所の詳細を出力しました。 何を推測しますか?間違った位置緯度/経度
私が試した次のことは、デバイスを回転させることです。私がデバイスがlandsacpeモードになっていたときに、場所の緯度/経度が変更されていることがわかりました私はどこにも行かなかった)と精度が上昇し、いくつかのケースでだから私はこのことを理解していない180
の値に達した:
はなぜ時々、デバイスの緯度/経度の値も異なっていますデバイスは机の上に横たわっていて移動しませんが?ローテーションがどのように位置精度に影響を与えますか?
マイコード:
public class LocationUpdateService extends Service implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
LocationListener
{
private GoogleApiClient googleApiClient;
private LocationRequest locationRequest;
private boolean playsServiceAvailable;
private String TAG = getClass().getSimpleName();
@Override
public void onCreate()
{
Log.d(TAG,"onCreate");
super.onCreate();
initRequestLocation();
playsServiceAvailable = checkPlayServicesConnection();
setupLocationApiClient();
}
@Nullable
@Override
public IBinder onBind(Intent intent)
{
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
Log.d(TAG, "onStartCommand");
super.onStartCommand(intent,flags,startId);
if (!playsServiceAvailable || googleApiClient.isConnected())
{
return START_STICKY;
}
setupLocationApiClient();
if (!googleApiClient.isConnected() || !googleApiClient.isConnecting())
{
Log.d(TAG, "onStartCommand: googleApiclient.connect()");
googleApiClient.connect();
}
return START_STICKY;
}
@Override
public void onDestroy()
{
Log.d(TAG, "onDestroy");
if (this.playsServiceAvailable && this.googleApiClient != null)
{
this.googleApiClient.unregisterConnectionCallbacks(this);
this.googleApiClient.unregisterConnectionFailedListener(this);
this.googleApiClient.disconnect();
this.googleApiClient = null;
}
super.onDestroy();
}
@Override
public void onConnected(@Nullable Bundle bundle)
{
try
{
LocationServices.FusedLocationApi.requestLocationUpdates(this.googleApiClient, locationRequest, this);
}
catch (SecurityException e)
{
e.printStackTrace();
}
}
@Override
public void onConnectionSuspended(int i)
{
googleApiClient = null;
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult)
{
}
@Override
public void onLocationChanged(Location currentLocation)
{
Log.d(TAG, "onLocationChanged:\n\t\t\t" +
"CurrentLocation:\n\t\t\t\t" +
"ACCURACY: " + currentLocation.getAccuracy() + "\n\t\t\t\t" +
"LAT: " + currentLocation.getLatitude() + "\n\t\t\t\t" +
"LONG: " + currentLocation.getLongitude() + "\n\t\t\t\t" +
"TIME: " + currentLocation.getTime());
}
private boolean checkPlayServicesConnection()
{
int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
if (resultCode != ConnectionResult.SUCCESS)
{
return false;
}
return true;
}
private void initRequestLocation()
{
locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(5000)
.setFastestInterval(1000);
}
private void setupLocationApiClient()
{
Log.d(TAG,"setupLocationApiClient");
if (googleApiClient == null)
initGoogleApiClient();
}
private synchronized void initGoogleApiClient()
{
Log.d(TAG,"initGoogleApiClient");
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addOnConnectionFailedListener(this)
.addConnectionCallbacks(this)
.build();
}
}
ありがとうございます。 – Elior
私もあなたのために回答を編集します。 –
OK ..それは働いているようです.. もし正しいとすれば、setSmallestDisplacementは場所が27メートルの違いがある場合にのみ更新されます(あなたの例では) – Elior