使用Google Maps API的3个字符的国家/地区代码 [英] 3 character country codes using google maps api

查看:95
本文介绍了使用Google Maps API的3个字符的国家/地区代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在Google地图的反向地理编码中获取3个字符的国家/地区代码?

Is there a way I can get the 3 char country code in Google maps's Reverse Geocoding?

以下查询返回2个字符的国家/地区代码(ISO 3166-1编码).但是我需要有3个字符的国家/地区代码. http://maps.google.com /maps/api/geocode/xml?latlng=40.714224,-73.961452&sensor=false

The below query returns the 2 char country code (ISO 3166-1 encoding). But I need to have the 3 char country code. http://maps.google.com/maps/api/geocode/xml?latlng=40.714224,-73.961452&sensor=false

推荐答案

您可以使用基于javascript多维数组的查找表,并使用 jquery

You can use a lookup table based on javascript multi dimensional array and using jquery

var countries = [
{"two" : "AF","three" : "AFG" },
{"two" : "AL","three" : "ALB" },
{"two" : "DZ","three" : "DZA" },
{"two" : "AS","three" : "ASM" },
{"two" : "AD","three" : "AND" },
{"two" : "AO","three" : "AGO" },
{"two" : "AI","three" : "AIA" },
{"two" : "AQ","three" : "ATA" },
{"two" : "AG","three" : "ATG" },
{"two" : "AR","three" : "ARG" },
{"two" : "AM","three" : "ARM" },
{"two" : "AW","three" : "ABW" }
];//etc

var getKeyByParameter = function(obj, parameter) {
var returnVal = "";

$.each(obj, function(key, info) {
    if (info.two == parameter) {
       returnVal = info.three;
        return false; 
    };   
});

return returnVal;       

}

console.log(getKeyByParameter(countries, 'AG'));

返回ATG

这篇关于使用Google Maps API的3个字符的国家/地区代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆