[使用Google Places api获取管理区域等级ISO代码

问题描述 投票:4回答:2

我正在开发需要使用格式传递用户状态的应用程序

country_iso_code-state_iso_code

我正在使用Google Places API自动完成功能来搜索我们的apps(Android,iOS和网络)中的城市:然后使用placeid来获取位置详细信息,方法是:

https://maps.googleapis.com/maps/api/place/details/json?key=[your_api_key]&placeid=ChIJJfXQAJr114URJwWCbKB4-yc

响应详细信息查询包含Administrative_area_level_1,它是“ administrative_area_level_1表示国家/地区级别以下的一阶公民实体。在美国,这些行政级别是州。并非所有国家/地区都显示这些行政级别。”

List iso代表所选国家/地区中每个“州”的代码。

我正在寻找有关如何将Administrative_area_level_1映射到其相应ISO代码的建议。任何帮助,将不胜感激。

我能想到的解决方案是使用详细信息查询响应中的长名称,并将其映射到根据服务器上的iso代码列表创建的字典。

android google-maps google-places-api iso google-geocoding-api
2个回答
0
投票

我们最终使用通过ISO代码和放置位置生成的地图创建了自己的微服务。因此,现在该应用向我们的微服务发出了次要请求,以获取此数据。


0
投票

对于javascript使用Google地方信息API获取Administrative_area_level_1 ISO代码

来源来源:http://www.expertsuggestion.com/

obj = JSON.parse(data);

   $('#searchname').val(obj.result.name);

    $('#addressset').val(obj.result.formatted_address);
 $('#webset').val(obj.result.website);
$('#imgset').val(obj.result.icon);

  for (i in obj.result.address_components) {

  for (j in (obj.result.address_components[i].types)) {

if (obj.result.address_components[i].types[j] == 'postal_code') {

    $('#zipcode').val(obj.result.address_components[i].long_name);

}

if (obj.result.address_components[i].types[j] == 'administrative_area_level_2') {

    $('#city').val(obj.result.address_components[i].long_name);
}

if (obj.result.address_components[i].types[j] == 'country') {
    console.log(obj.result.address_components[i].long_name);

    $("#country-select").find("option:contains('" + obj.result.address_components[i].long_name + "')").attr('selected', true);

}

if (obj.result.address_components[i].types[j] == 'administrative_area_level_1') {
    console.log(obj.result.address_components[i].long_name);
    $("#state-select").find("option:contains('" + obj.result.address_components[i].long_name + "')").attr('selected', true);

}

  }

}
© www.soinside.com 2019 - 2024. All rights reserved.