如何提高 GPS 坐标的精度?

Posted

技术标签:

【中文标题】如何提高 GPS 坐标的精度?【英文标题】:How to increase the accuracy of the GPS coordinates? 【发布时间】:2020-11-15 23:46:46 【问题描述】:

目前,我正在使用 GPS 坐标来获取用户的地址,如下所示, 私人无效 findAddress()

Geocoder geocoder;
List<Address> addresses;
geocoder=new Geocoder(this, Locale.getDefault());

        try
            addresses=geocoder.getFromLocation(lattitude,longitude,1);
            String address=addresses.get(0).getAddressLine(0);
            String city=addresses.get(0).getLocality();
            String state=addresses.get(0).getAdminArea();
            String country=addresses.get(0).getCountryName();

            countryEt.setText(country);
            stateEt.setText(state);
            cityEt.setText(city);
            addressEt.setText(address);


         catch (IOException e) 
            Toast.makeText(this, ""+e.getMessage(), Toast.LENGTH_SHORT).show();
        

    

位置权限如下,

 private void detectLocation() 
        Toast.makeText(this, "Please Wait..", Toast.LENGTH_LONG).show();
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) 
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

    

这段代码完全没问题。但是准确率很低。我怎样才能提高我的准确性。要进行哪些修改?如果有人告诉我正确的流程,我很高兴。

【问题讨论】:

“但准确率低”——这是什么意思? “我怎样才能提高我的准确性”——走出去,远离高楼。从编程的角度来看,你所拥有的一切都很好。 @CommonsWare 它显示了地址。但是那个地址是不正确的。距离确切地址100m-200m。但是,如果我使用了一些应用程序,例如 uber,它会正确检测到地址。我也希望我的代码具有这种类型的准确性。可能吗?要进行哪些修改? 我猜想找一个更好的地理定位服务,然后用它代替Geocoder。 “但如果我使用了一些应用程序,例如 uber,它会正确检测到地址”——在您所在的位置可能就是这种情况。在我所在的位置,Uber 的地址解析很差。 【参考方案1】:

如果你在电脑前,我想你是在建筑物里,gps 信号不好。试着走上街头。此外,您可以使用监听器设置requestLocationUpdates,并每隔 1-1.5 秒发出一次定时请求,直到精度低于 50 米或 30... 最后取消注册监听器。 这是一个示例:

@SuppressLint("MissingPermission")
private Task<Void> startMyLocationUpdates(int interval) 
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(ctx);
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(interval);   //1,5 seconds
mLocationRequest.setFastestInterval(interval);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
return mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());

【讨论】:

【参考方案2】:

尝试使用 RAW GNSS 测量 API 并获取位置。

【讨论】:

以上是关于如何提高 GPS 坐标的精度?的主要内容,如果未能解决你的问题,请参考以下文章

为啥 CLLocation 坐标在显示时会失去精度?

Android GPS以不同的精度返回相同的位置坐标

手持GPS西安80坐标系参数

html5 如何调用安卓手机获取gps坐标

比较具有一定余量的 GPS 坐标

使用 GPS 坐标计算最短距离