[英]How to get address from latitude and longitude android?
我有一个应用程序,将获得用户位置的纬度和经度。 我需要知道的是如何获取位置的经度和纬度并将其转换为用户的地址?
谢谢你的帮助。
try {
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(MainActivity.this);
Toast.makeText(this, "before if",
Toast.LENGTH_LONG).show();
if (latitude != 0 || longitude != 0) {
addresses = geocoder.getFromLocation(latitude ,
longitude, 1);
String address = addresses.get(0).getAddressLine(0);
String city = addresses.get(0).getAddressLine(1);
String country = addresses.get(0).getAddressLine(2);
Log.d("TAG", "address = "+address+", city ="+city+", country = "+country );
Toast.makeText(this, "address = "+address+", city ="+city+", country = "+country, Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(this, "latitude and longitude are null",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
尝试使用Geocoder
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.