android - 如何使用 fusedLocation 获得良好的准确性?
问题描述
在我的应用程序中,我需要跟踪用户位置。为此,我正在使用FusedLocation
,从中,我每 10 秒询问一次位置。不幸的是,返回的位置精度为 500.0 米或 164O 英尺。在Android FusedLocation
doc中,规定
精确到几英尺内的位置更新
我的请求设置为:
LocationRequest locationRequest = new LocationRequest();
locationRequest.setSmallestDisplacement(10);
locationRequest.setInterval(30000); // 30 s
locationRequest.setFastestInterval(10000); // 10 s
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
另外,我要求粗略和精细位置的许可。
我怎样才能获得更好的准确性?
解决方案
也许您可以尝试询问位置表格,NETWORK_PROVIDER
这有助于我解决用户最后已知位置的问题。
这是我的处理方式:
LocationManager locationManager;
locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, locationListener);
Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
LatLng userLocation = new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude());
让我知道这是否对您有帮助:)
此致,
迪米塔尔·格奥尔基耶夫
推荐阅读
- android - 现代 android 消息应用程序如何在没有前台的情况下工作
- flutter - 如何防止platformViewRegistry出错[flutter-web]
- dns - 如何在 Cockpit 中设置 oVirt 引擎?我收到“部署失败”错误
- r - 无法在 R 中将 xgboost 模型导出为 pmml 格式
- javascript - 我可以为一个组件导入整个库吗
- html - 通过单击具有特定类的框获取值或 ID
- python-3.x - 从 Python 中一列的开头和结尾删除空格和标点符号(括号除外)
- java - 如何使用改造android将JSONArray中的多个jsonobjects发送到api
- dynamic - 如何在安装期间将参数动态传递给 RPM
- python - savefig() 不将任何内容保存到文件夹中