GPS坐标的国家名称

时间:2010-09-03 06:34:00

标签: geolocation gis reverse-geocoding

是否有一种简单的方法可以获得特定点所在国家/地区的名称?

我不太关心准确性,也不关心政治纠纷所带来的含糊之处。只需要一个足够好的近似值。

6 个答案:

答案 0 :(得分:6)

编辑: Yahoo Where API不再可用。

试试Yahoo! APIs

  

纬度和经度

     

纬度和   经度可以指定   位置参数。纬度和   经度可以表示为十进制   度或度 - 分 - 秒,   无论是领先还是尾随   方向或主要标志。如果   提供方向,经度   可能出现在纬度之前。如果   没有指示方向,   经度可能出现在纬度之前   如果它超出-90到90的范围。   否则,必须出现纬度   第一。标点符号(逗号,   度,分,秒)   忽略。

Examples: 

•50.3 -120.5
•50.3, -120.5
•-120.5 50.3
•50.3 N 120.5 W
•120.5 W 50.3 N
•50 18 0 -120 30 0
•50 18 0 N 120 30 0 W
•50° 18' 0" N 120° 30' 0" W

响应元素会为您提供国家/地区以及许多其他elements

不要忘记发送参数gflags = R,以进行反向地理编码。如果你想在json中输出,也可以发送参数flags = J.

答案 1 :(得分:5)

如何使用google's reverse geo-encoding服务?

答案 2 :(得分:5)

仅供参考,geonames.org也有一个很好的网络服务,但速度有限(因为我不得不查找一大批坐标,这是我的问题)。

示例:http://ws.geonames.org/findNearbyPlaceName?lat=47.3&lng=9

答案 3 :(得分:1)

以下是一些JavaScript代码,用于从纬度和经度坐标中获取国家/地区的名称:


  1. 使用Google的地理编码服务[jsfiddle]

    var lookupCountryWithGoogle = function(lat,lng){     var latlng = new google.maps.LatLng(lat,lng);

    var geoCoder = new google.maps.Geocoder();
    
    geoCoder.geocode({
        location: latlng
    }, function(results, statusCode) {
        var lastResult = results.slice(-1)[0];
    
        if (statusCode == 'OK' && lastResult && 'address_components' in lastResult) {
            alert('coordinates: ' + lat + ', ' + lng + '\n' + 'country: ' + lastResult.address_components.slice(-1)[0].long_name);
        } else {
            alert('coordinates: ' + lat + ', ' + lng + '\n' + 'failed: ' + statusCode);
        }
    });
    

    };

    lookupCountryWithGoogle(43.7534932,28.5743187); // 将会成功 lookupCountryWithGoogle(142,124); //将失败

  2. (您需要从maps.google.com/maps/api/js?sensor=false&fake=.js等网址加载Google对此的JavaScript支持)


    1. 使用ws.geonames.org [jsfiddle]

      var lookupCountryWithGeonames = 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' + 'country: ' + results.countryName);
          } else {
              alert('coordinates: ' + lat + ', ' + lng + '\n' + 'failed: ' + results.status.value + ' ' + results.status.message);
          }
      });
      

      };

      lookupCountryWithGeonames(43.7534932,28.5743187); //将成功

      lookupCountryWithGeonames(142,124); // 将失败

答案 4 :(得分:0)

您还可以查看tinygeocoder提供的服务。

另一种方法是从自然地球(或其他来源)下载国家地图。使用Geotools,您可以搜索该点是否位于其中一个国家/地区内。

答案 5 :(得分:0)

Geonames API有所更改。此处更多信息:https://www.geonames.org/export/web-services.html

该页面上的工作示例:

curl "http://api.geonames.org/countryCode?lat=47.03&lng=10.2&username=demo"