2012-05-26 38 views
2

我正在查找一個API,它返回在給定座標的國家/地區使用哪種語言。有誰知道這樣的事情是否存在?Geocode to language

+0

協調,國家查找使用這樣的回答: http://stackoverflow.com/a/3666861/317706在國內使用的語言: http://stackoverflow.com/a/1876170/317706 – user317706

回答

0

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