android - Google Place API SDK 国家/地区代码 - 如何?
问题描述
使用 google Place API Android SDK。无论如何从地点对象中检索国家名称/国家代码?
它在 IOS sdk 中的 address_components 中确实有,但在 Android SDK 中找不到相同的元素。
任何想法?
解决方案
https://maps.googleapis.com/maps/api/geocode/json?latlng=lati,longi&key=myApiKey
如果您正在寻找详细信息,您也可以从 Google Place API 检查下面的 API 解析 JSON ,
https://developers.google.com/places/web-service/details https://developers.google.com/places/web-service/autocomplete
或者
查找以下代码以获取当前国家/地区或通过纬度和经度获取国家/地区。
public static String getCountryName(Context context, double latitude, double longitude) {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
List<Address> addresses;
try {
addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (addresses != null && !addresses.isEmpty()) {
return addresses.get(0).getCountryName();
}
} catch (IOException ioe) { }
return null;
}
[1]: http://
推荐阅读
- java - 我可以将 Socket.io 与 Spring-boot 一起使用吗?
- amazon-s3 - S3 - 使用批处理操作和 crr 复制大量数据,而不会丢失文件
- python - python中URL的正则表达式
- android - 在 Flutter 中的操作栏和标题之间添加一些空格
- java - 硒测试用例从主菜单中选择子菜单
- plugins - Matomo - 位置提供程序插件和访问详细信息
- c - 正整数相乘得到 0 (__int64)
- c++ - SSH 在 QProcess 中不起作用,但在控制台中起作用
- python-2.7 - exe文件运行期间出错但是.py文件运行良好
- c# - WPF DataGrid:使每一行的列类型动态化