Ich habe Google Play Service Fused Location Api in meiner App implementiert, um kontinuierlich Benutzer Ort zu erhalten. Alles funktioniert gut, wenn Wi-Fi aufFused Location Provider API Ort von GPS erhalten, wenn WLAN ausgeschaltet ist
ist, aber wenn ich WLAN wende dann aktualisieren Benutzer Ort mit Handy-Informationen, so dass die Genauigkeit mehr als 700 Meter ist.
was ich will ist, wenn wifi ausgeschaltet ist dann erhalten benutzer standort von GPS.
protected synchronized void buildGoogleApiClient() {
Log.i(TAG, "Building GoogleApiClient");
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
createLocationRequest();
}
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);
}
@Override
public void onConnected(Bundle connectionHint) {
Log.i(TAG, "Connected to GoogleApiClient");
if (mCurrentLocation == null) {
mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());
updateUI();
}
if (mRequestingLocationUpdates) {
startLocationUpdates();
}
}
@Override
public void onLocationChanged(Location location) {
mCurrentLocation = location;
mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());
updateUI();
Toast.makeText(this, getResources().getString(R.string.location_updated_message),
Toast.LENGTH_SHORT).show();
}
fügen Sie dies zu Ihrem mlocationRequest 'mlocationRequest.setSmallestDisplacement (5);' –
Dies wird nur 5m Verschiebung für die Aktualisierung setzen. –
Dies erhöht die Genauigkeit, da sich der Standort des Benutzers bei einer Standortänderung von mehr als 5 Metern ändert –