улучшить положение GPS - PullRequest
       27

улучшить положение GPS

0 голосов
/ 06 декабря 2018

Я использую этот код ниже, чтобы определить положение пользователя, и он работает с точностью = 20, и я получаю широту и долготу, но иногда точность составляет более 70, а larLong не верны, так что это можно улучшитьэто, чтобы получить лучшие результаты, спасибо

    public Location getLocation() {

    locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setAltitudeRequired(true);
    criteria.setSpeedRequired(true);
    criteria.setCostAllowed(true);
    criteria.setBearingRequired(true);
    //API level 9 and up
    criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
    criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
    criteria.setBearingAccuracy(Criteria.ACCURACY_HIGH);
    criteria.setSpeedAccuracy(Criteria.ACCURACY_HIGH);

    String provider = locationManager.getBestProvider(criteria,true);

    if(provider!=null && !provider.equals("")){
        Log.e("provider",provider);
        locationManager.requestLocationUpdates(provider,
                MIN_TIME_BW_UPDATES,
                MIN_DISTANCE_CHANGE_FOR_UPDATES,this);
    }else {
        locationManager.requestLocationUpdates(
                MIN_TIME_BW_UPDATES,
                MIN_DISTANCE_CHANGE_FOR_UPDATES,criteria, this,null);
    }


    Location networkLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    Location gpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    if (networkLocation != null) {
        Log.e("location","networkLocation");
        location=networkLocation;
        latitude = location.getLatitude();
        longitude = location.getLongitude();
        accuracy = location.getAccuracy();
    } else if (gpsLocation != null) {
        Log.e("location","gpsLocation");
        location=gpsLocation;
        latitude = location.getLatitude();
        longitude = location.getLongitude();
        accuracy = location.getAccuracy();
    }else {
        this.canGetLocation=false;
    }

    stopUsingGPS();

    return location;
}
...