gpt4 book ai didi

java - 国家/地区代码 (iso-3166-1/iso-3166-2) 到经度和纬度

转载 作者:行者123 更新时间:2023-11-29 03:12:08 32 4
gpt4 key购买 nike

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

例子:

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

我一直在四处搜索,但没有找到完整的 list ,或者理想情况下,没有找到执行此操作的 Java 库。

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

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

最佳答案

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

我找到了 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 列表

关于java - 国家/地区代码 (iso-3166-1/iso-3166-2) 到经度和纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28794252/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com