2

我在这里有点挣扎,我正在使用 Fused API 来获取位置更新。我的目的是当用户走路时在地图上画一条路径。

我已实现如下:

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.map_layout, container, false);

        // some other initialization
        //....
        //
        if (mGoogleApiClient == null) {
            mGoogleApiClient = new GoogleApiClient.Builder(mContext)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .addApi(LocationServices.API)
                    .build();
        }

        return view;
    }

然后我通过以下方法开始这些东西

private void startReceivingLocationUpdates() {
        if (checkGPSPermission() && mGoogleApiClient.isConnected() && !isReceivingLocationUpdates) {
            LocationRequest locationRequest = new LocationRequest();
            locationRequest.setInterval(5000);
            locationRequest.setFastestInterval(5000);
            locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
            LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,
                    locationRequest, this);
            isReceivingLocationUpdates = true;
        }
    }

&在这里我收到位置更新

@Override
    public void onLocationChanged(Location location) {
      if(getDistanceBetweenTwoLacation(mCoordinates.get(mCoordinates.size() - 1), location) > 3d) {
            for(int i= 0; i < mCoordinates.size(); i++) {
                Location locationTemp = mCoordinates.get(i);
                Log.d(TAG, "i => " + i + " Lat => " + String.valueOf(locationTemp.getLatitude()) + " Lng => " + String.valueOf(locationTemp.getLongitude()));
            }
            if(mCoordinates.size() > 0)
                Log.d(TAG, "lat difference is => " + getDistanceBetweenTwoLacation(mCoordinates.get(mCoordinates.size() - 1), location));
            mCoordinates.add(location);
        }
    }

现在的问题是,onLocationChanged即使设备在同一个地方稳定,也会多次给出与过去位置的差异/距离约为 5-90 米的 lat-lng 位置。我错过了什么吗?

顺便说一句,这是返回我使用的两个 lat-lngs 距离的方法

private double getDistanceBetweenTwoLacation(Location origin, Location destination) {
        return origin.distanceTo(destination);
    }
4

1 回答 1

2

在室内时,GPS 定位不准确(以及移动/漂移/跳跃)非常普遍。如果没有清晰的天空视野,就不可能进行准确的 GPS 定位。在您的Location对象中,有一个getAccuracy()返回浮点数的方法。该值是以米为单位的定位精度,置信度为 68%(1 个标准偏差),代表圆的半径。

在室内,您可能会看到 20、30 甚至 50 米的准确度值,而纬度和经度在该距离内跳跃。一旦在户外,准确度值应该会下降到 10 米以下,通常会低于 5 米,并且您的位置会更频繁地跳来跳去。

tl;dr:GPS 在室内不能给出准确的结果。

于 2016-08-03T15:14:38.260 回答