【问题标题】:Country/region codes (iso-3166-1/iso-3166-2) to longitude and latitude国家/地区代码 (iso-3166-1/iso-3166-2) 到经度和纬度
【发布时间】:2015-05-01 21:18:13
【问题描述】:

我需要将 iso-3166-1/iso-3166-2 代码转换为经度/纬度

例子:

  • 输入:“美国”,输出:(37.09024, -95.71289100000001)。
  • 输入“VE-O”,输出:(10.9970723, -63.91132959999999)。

我一直在四处搜索,但没有找到完整的列表,或者理想情况下,找不到一个 Java 库。

This Github project 很有前途,但缺少很多地区的很多地理位置信息。

请注意,与问题 Need a list of all countries in the world, with a longitude and latitude coordinate 不同,此问题指的是区域细分 (iso-3166-2)。

【问题讨论】:

标签: java geolocation geocoding


【解决方案1】:

由于我没有得到任何答案,我将解释我是如何解决的。

我找到了 iso-3166-1 国家代码中心的这个 csv 列表:http://dev.maxmind.com/geoip/legacy/codes/country_latlon/(我不得不进行一些手动调整)

至于 iso-3166-2 区域质心,我最终创建了一个 shell 脚本,该脚本使用 Google Maps API 以 csv 格式打印区域质心(请注意,我没有验证完整的输出,但我的案例检查是否正确)。这是使用curl 和jq 处理API 输出的脚本的简化版本:

#!/bin/bash

# Example list of regions (full list can be obtained from https://www.ip2location.com/free/iso3166-2 )
REGIONS="VE-O GB-BKM GB-CAM GB-CMA"

for REGION in $REGIONS; do 
LATLON=$(curl -s "maps.googleapis.com/maps/api/geocode/json?sensor=false&address=$REGION" | jq -r '.results[0].geometry.location.lat,@text ",",.results[0].geometry.location.lng')
echo $REGION , $LATLON |  tr -d ' '
done

然后我使用 Apache Commons CSV 在我的 java 代码中导入了 csv 列表

【讨论】:

  • 只是一点。这可能违反 Google Maps/Google Earth APIs 服务条款developers.google.com/maps/terms 第 10.5.d 节“禁止缓存或存储。您不会预取、缓存、索引或存储任何要在服务之外使用的内容... "
【解决方案2】:

这些是我在解决这个问题时发现的最佳资源:

国家坐标: http://dev.maxmind.com/geoip/legacy/codes/country_latlon/

ISO 3166-2 坐标: https://github.com/oodavid/iso-3166-2/blob/master/iso_3166_2.js

【讨论】:

    猜你喜欢
    • 2014-02-09
    • 2012-12-16
    • 2015-02-22
    • 2013-12-03
    • 2011-12-19
    • 2014-08-29
    • 2021-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多