如何提高GPS坐标的准确性?
How to increase the accuracy of the GPS coordinates?
目前,我正在使用 GPS 坐标获取用户地址,如下所示,
private void 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);
}
这段代码完全没问题。但准确率较低。我怎样才能提高我的准确性。要进行哪些修改?如果有人告诉我正确的流程,我很高兴。
如果你在电脑前,我想你在建筑物里,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());
尝试使用 RAW GNSS 测量值 API 并获取位置。
目前,我正在使用 GPS 坐标获取用户地址,如下所示, private void 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);
}
这段代码完全没问题。但准确率较低。我怎样才能提高我的准确性。要进行哪些修改?如果有人告诉我正确的流程,我很高兴。
如果你在电脑前,我想你在建筑物里,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());
尝试使用 RAW GNSS 测量值 API 并获取位置。