gpt4 book ai didi

android - 如何从纬度和经度获得完整的地址?

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

我想从 android 中的纬度和经度中获取以下值

  1. 街道地址
  2. 城市/州
  3. zip
  4. 完整地址

如何做到这一点?

最佳答案

Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());

addresses = geocoder.getFromLocation(latitude, longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5

String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String city = addresses.get(0).getLocality();
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
String postalCode = addresses.get(0).getPostalCode();
String knownName = addresses.get(0).getFeatureName(); // Only if available else return NULL

有关可用详细信息的更多信息,请查看 Android-Location-Address

关于android - 如何从纬度和经度获得完整的地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9409195/

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