gpt4 book ai didi

android - 在android上使用经度和纬度指定国家名称

转载 作者:行者123 更新时间:2023-12-04 16:35:38 25 4
gpt4 key购买 nike

我在 android 模拟器上使用 google api 15。

我想通过触摸屏幕从 map 上指定一个国家,
所以如果我在某个经度和纬度上触摸屏幕,我可以知道它们属于哪个国家或哪个城市?

.. 非常感谢。

最佳答案

你可以尝试这样的事情:

public static String getCountryName(Context context, double latitude, double longitude) {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocation(latitude, longitude, 1);
Address result;

if (addresses != null && !addresses.isEmpty()) {
return addresses.get(0).getCountryName();
}
return null;
} catch (IOException ignored) {
//do something
}

}

关于android - 在android上使用经度和纬度指定国家名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9948942/

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