从coord android获得一个地址

时间:2018-05-13 00:56:49

标签: java android google-maps

我实际上正在使用地图' Android应用程序的API,我需要从2个coords得到一个地址。所以,有人知道如何将Lat,Lng转换为adresse? 如果不能得到一个地方,是否有可能在这一点附近获得一个位置?

提前感谢!

1 个答案:

答案 0 :(得分:1)

使用地理编码器。

Geocoder geocoder;
List<Address> yourAddresses;
geocoder = new Geocoder(this, Locale.getDefault());
yourAddresses= geocoder.getFromLocation(yourLatitude, yourLongitude, 1);

if (yourAddress.size() > 0)
{
 String yourAddress = yourAddresses.get(0).getAddressLine(0);
 String yourCity = yourAddresses.get(0).getAddressLine(1);
 String yourCountry = yourAddresses.get(0).getAddressLine(2);
}