【发布时间】: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 的地址解析很差。
标签: android latitude-longitude android-gps