如何获得准确的GPS坐标Android LocationServices

时间:2016-08-12 13:35:02

标签: android gps location-services

我只想弄清楚我能做些什么来确保从移动设备获得精确的GPS坐标。当我将距离加在一起时,我得到了一个疯狂的阅读,当手机没有从我的桌子移开时,我已经走了8米。我不知道是不是因为我设置了LocationRequest的方式。我在谷歌上读到一些关于GPS坐标的准确率是68%,有些读数可能会超出68%...也许我应该做些什么来消除不准确的读数?

这是我创建的位置请求,因此我可以收到位置更新:

    private void createLocationRequest() {
        locationRequest = new LocationRequest();
        locationRequest.setInterval(5000);
        locationRequest.setFastestInterval(2000);
        locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

//Some other code below which checks location settings
}

这是我的onLocationChanged ...这是我获取新位置的更新,然后计算两点之间的距离:

  @Override
public void onLocationChanged(Location location) {
    //For the first location update, we will assume this is the starting point
    if (currentLocation == null) {
        currentLocation = location;
    }
    float distance = 0L;
    double height = 0;
    double speed = 0;
    height = location.getAltitude();

    if (runStarted && !runPaused) {
        locationsList.add(location); //This adds the current location to the list
        runnerLocations.add(location); //This adds the current route the runner is running (without pauses)
    } else {
        locationsList.add(location);
    }

    //Calculate the distance from the last recorded gps point
    if (currentLocation != null && runStarted && !runPaused){
        distance = currentLocation.distanceTo(location);
    }
    currentLocation = location;

    //move the map view to the user's current location, regardless of their running state (paused or run)
    mapObject.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 18));

    if (runStarted && !runPaused) {
        if (location.getSpeed() > 0) {
            speed = location.getSpeed() * 3.6;// convert m/sec to km/h
        }
        DecimalFormat format = new DecimalFormat("###.##");
        speed = Double.valueOf(format.format(speed));
        recordedSpeeds.add(speed);
        totalDistance = totalDistance + distance;
        updateUI(speed, location, distance);
        if (height > 0) {
            height = Double.valueOf(format.format(height));
        }
        calculateCurrentCaloriesBurnt(height, speed);
    }
}

我正考虑用一些公式手动计算距离。我还能尝试什么来获得准确的距离计算?

1 个答案:

答案 0 :(得分:0)

你可以做几件事来获得更准确的读数:

  1. 使用设备的加速度计确定设备是否静电,仅在设备移动时累加距离。

  2. 当您移动时,忽略精确度低于某个阈值的读数,例如确定阈值是20m,并忽略读数精度> 20米。