앱에서 Google Play 서비스의 융합 위치 API를 구현하여 사용자 위치를 지속적으로 확보했습니다. Wi-Fi를 사용할 때 모든 것이 잘 작동합니다.융합 위치 제공 업체 Wi-Fi가 꺼져있을 때 Gps에서 위치 정보 가져 오기
그러나 Wi-Fi를 끄면 셀룰러 정보를 사용하여 사용자 위치를 업데이트하므로 정확도가 700 미터 이상이됩니다.
내가 원하는 것은 wifi가 꺼져있을 때 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();
}
이것을 mLocationRequest에 추가하십시오. 'mLocationRequest.setSmallestDisplacement (5);' –
이것은 업데이트를 위해 단지 5m 이동을 설정합니다. –
사용자 위치가 5 미터 이상 변경되면 위치 업데이트가 실행되므로 정확도가 높아집니다. –