【问题标题】:Region/counties google place codes?地区/县谷歌地方代码?
【发布时间】:2015-08-11 10:29:09
【问题描述】:

任何人都知道 google 放置的 ISO 格式返回区域的地点对象 short_name 吗?

我有这个代码:

var place = places.getPlace();
    var type = place.address_components[0].types[0];
switch(type) {
    case 'country':         document.getElementById('country').value=place.address_components[0].short_name;
        break;
    case 'locality':
        document.getElementById('town').value=place.address_components[0].long_name;
        break;
    default: //when is not a country or a city
           document.getElementById('regioncode').value=place.address_components[0].short_name

;

如果是一个地区/县,它会获取它的 shor_name,但在某些情况下,它会返回一个代码,例如搜索“西班牙巴利阿里群岛”,它会返回“PM”(代表 ISO 3166-2:ES) ,但如果我搜索“Kalmar län, Sweden”,我得到的 short_name 与 long_name 完全相同,即“Kalmar County”而不是“H”(代表 ISO 3166-2:SE)所以我的问题是:为什么有时谷歌返回地区/县的 ISO 3166-2 值,有时返回 long_name 值,这背后有什么逻辑吗?我可以强制只返回短名称的 ISO 值吗???谢谢

【问题讨论】:

    标签: google-maps google-places-api


    【解决方案1】:

    Google Documentation

    short_name 是地址组件的缩写文本名称, 如果可供使用的话。例如,用于状态的地址组件 阿拉斯加可能有一个长名“阿拉斯加”和一个短名“AK”,使用 2 个字母的邮政缩写。

    这里的关键词是“如果可用”。卡尔马县不得有简称

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多