2

Google マップのリバース ジオコーディングで 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 に答える