【问题标题】:Geocode to language地理编码到语言
【发布时间】:2023-03-24 14:21:01
【问题描述】:

我正在寻找一个 API,它可以返回给定坐标所在国家/地区使用的语言。有谁知道这样的事情是否存在?

【问题讨论】:

标签: geocoding latitude-longitude


【解决方案1】:

ws.geonames.org 提供此服务。这是一些使用 JavaScript 和 jQuery 的示例代码,但您可以使用任何语言访问它:

var lookupLanguagesWithGeonames = function(lat, lng) {

    $.getJSON('http://ws.geonames.org/countryCode', {
        lat: lat,
        lng: lng,
        type: 'JSON'
    }, function(results) {
        if (results.countryCode) {
            alert('coordinates: ' + lat + ', ' + lng + '\n' + 'languages: ' + results.languages);
        } else {
            alert('coordinates: ' + lat + ', ' + lng + '\n' + 'failed: ' + results.status.value + ' ' + results.status.message);
        }
    });
};

// Coordinates that fall within a country
lookupLanguagesWithGeonames(43.7534932, 28.5743187);

// Coordinates which are not within any country
lookupLanguagesWithGeonames(142, 124);​

jsfiddle link

【讨论】:

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