2

有没有办法在谷歌地图的反向地理编码中获得 3 个字符的国家代码?

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

4

1 回答 1

1

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'));

Returns ATG

于 2013-03-25T22:17:27.093 回答