gpt4 book ai didi

android - 如何在 android 中仅从 lat, long 获取 City, State, Country

转载 作者:IT老高 更新时间:2023-10-28 23:28:42 25 4
gpt4 key购买 nike

我有以下代码将 lat、long 转换为人类可读的地址。现在我正在获取完整的详细信息,包括街道名称。我怎样才能只得到城市、州、国家?我不想要更多细节。请帮我。

Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(latitude, longitude, 1);

String add = "";
if (addresses.size() > 0)
{
for (int i=0; i<addresses.get(0).getMaxAddressLineIndex();i++)
add += addresses.get(0).getAddressLine(i) + "\n";
}

showToastMessage(add);
}
catch (IOException e1) {
e1.printStackTrace();
}

最佳答案

对来自地址的对象使用以下方法:

getLocality()

getCountryName()

使用

getAdminArea() 返回状态。

我不知道这对于其他国家/地区有多准确,但对于美国的地址,这会返回正确的州名。

附:很抱歉写了一个完整的单独答案,我还不能发表评论。

关于android - 如何在 android 中仅从 lat, long 获取 City, State, Country,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12673357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com