gpt4 book ai didi

android - 从我的位置查找城市名称

转载 作者:行者123 更新时间:2023-11-29 21:13:17 25 4
gpt4 key购买 nike

有什么方法可以让我从当前位置 (Android) 获取城市名称?我知道如何获得 lattitue/long 但如果有一个具体的例子那就更好了

谢谢

最佳答案

     Geocoder gcd = new Geocoder(context, Locale.getDefault());
try{
List<Address> addresses = gcd.getFromLocation(lat, lon, 1);//lat and lon is the latitude and longitude in double
if (addresses.size() > 0)
String cityName=addresses.get(0).getLocality();
}
catch (IOException e) {}
catch (NullPointerException e) {}

关于android - 从我的位置查找城市名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22131862/

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