Java 即使手机处于高精度状态,使用GPS进行距离计算也会产生误差

Java 即使手机处于高精度状态,使用GPS进行距离计算也会产生误差,java,android,gps,android-gps,Java,Android,Gps,Android Gps,我的一个应用程序p-Cab在计算以公里为单位的距离时遇到问题。对于驾驶员应用程序,我设置了取货位置,然后驾驶员开始驾驶汽车。根据行驶的“公里数”,向用户收取出租车费。为了获得最佳效果,我每一分钟计算一次距离,以便每一分钟计算一次收货位置,并将每一分钟所覆盖的距离相加。我遇到的问题是,大多数情况下,GPS定位错误,因此对于5公里的行驶,它给出的结果是10公里或15公里 以下是我用于获取GPS的服务: // The minimum distance to change Updates in mete

我的一个应用程序p-Cab在计算以公里为单位的距离时遇到问题。对于驾驶员应用程序,我设置了取货位置,然后驾驶员开始驾驶汽车。根据行驶的“公里数”,向用户收取出租车费。为了获得最佳效果,我每一分钟计算一次距离,以便每一分钟计算一次收货位置,并将每一分钟所覆盖的距离相加。我遇到的问题是,大多数情况下,GPS定位错误,因此对于5公里的行驶,它给出的结果是10公里或15公里

以下是我用于获取GPS的服务:

// The minimum distance to change Updates in meters
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 4; // 10 meters

// The minimum time between updates in milliseconds
private static final long MIN_TIME_BW_UPDATES = 1000 * 10 * 1; // 1 minute

// Declaring a Location Manager
protected LocationManager locationManager;

public GPSTracker(Context context) {
    this.mContext = context;
    getLocation();
}

public Location getLocation() {
    try {
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        locationManager = (LocationManager) mContext
                .getSystemService(LOCATION_SERVICE);
        String provider = locationManager.getBestProvider(criteria, true);
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

        }
        // getting GPS status
        isGPSEnabled = locationManager
                .isProviderEnabled(LocationManager.GPS_PROVIDER);

        // getting network status
        isNetworkEnabled = locationManager
                .isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        if (!isGPSEnabled && !isNetworkEnabled) {
            // no network provider is enabled
        } else {
            this.canGetLocation = true;
            // First get location from Network Provider
            if (isNetworkEnabled) {
                locationManager.requestLocationUpdates(
                        LocationManager.NETWORK_PROVIDER,
                        MIN_TIME_BW_UPDATES,
                        MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                Log.d("Network", "Network");
                if (locationManager != null) {
                    location = locationManager.getLastKnownLocation(provider);
                    if (location != null) {
                        latitude = location.getLatitude();
                        longitude = location.getLongitude();
                    }
                }
            }
            // if GPS Enabled get lat/long using GPS Services
            if (isGPSEnabled) {
                if (location == null) {
                    locationManager.requestLocationUpdates(
                            LocationManager.GPS_PROVIDER,
                            MIN_TIME_BW_UPDATES,
                            MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                    Log.d("GPS Enabled", "GPS Enabled");
                    if (locationManager != null) {
                        location = locationManager.getLastKnownLocation(provider);
                        if (location != null) {
                            latitude = location.getLatitude();
                            longitude = location.getLongitude();
                        }
                    }
                }
            }
        }

    } 
    return location;
   }
}

计算距离所用的方法给出了空中距离。 直接从源头到目的地,而不是路线距离。您必须使用google places API:

字符串url=“

这里需要传递三个参数原点、目的地和模式, 原点:原点位置, 目的地:目的地位置, 模式:在你的情况下,它将驾驶

完整的url将是:


嗨,尼特什,我也尝试过这种方法,但没有得到完美的结果,我认为问题在于位置的选择。