Google Place API SDK国家/地区代码-如何?

时间:2018-09-11 14:23:18

标签: android google-places-api

使用Google Place API Android SDK。 无论如何,是否有从地点对象中检索国家名称/国家/地区代码的信息?

它确实在address_components的IOS sdk中具有,但在Android SDK中找不到相同的元素。

有什么主意吗?

1 个答案:

答案 0 :(得分:0)

https://maps.googleapis.com/maps/api/geocode/json?latlng=lati,longi&key=myApiKey

您可以从Google Place API解析JSON
如果您正在寻找详细信息,也请查看下面的API,

https://developers.google.com/places/web-service/details https://developers.google.com/places/web-service/autocomplete

OR

查找以下代码以获取当前国家或通过纬度和经度以获取国家/地区。

        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://