国家/地区代码(iso-3166-1 / iso-3166-2)为经度和纬度 [英] Country/region codes (iso-3166-1/iso-3166-2) to longitude and latitude

查看:3665
本文介绍了国家/地区代码(iso-3166-1 / iso-3166-2)为经度和纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

例子:
$输入:US,输出:(37.09024,-95.71289100000001)。

  • 输入VE-O,输出:(10.9970723 ,-63.91132959999999)。


    我一直在四处搜寻,但未能找到完整的列表或理想的Java库。



    此Github项目是有希望的,但是很多地区缺少大量的地理位置信息。 注意,与需要列出世界上所有国家的经纬度坐标,这个指的是区域细分(iso-3166 -2)。

    解决方案

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



    我发现了iso-3166-1国家代码质心的csv列表: http://dev.maxmind.com/geoip/legacy/codes/country_latlon/ (我必须做一些手动调整)



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

     #!/ bin / bash 

    #区域示例列表(完整列表可从https://www.ip2location.com/free/iso3166-2获得)
    REGIONS =VE-O GB-BKM GB-CAM GB-CMA

    为REGION的$ REGIONS;做
    LATLON = $(curl -smaps.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

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


    I need to convert from iso-3166-1/iso-3166-2 codes to longitude/latitude

    Examples:

    • Input: "US", Output: (37.09024, -95.71289100000001).
    • Input "VE-O", Output: (10.9970723, -63.91132959999999).

    I have been searching around but failed to find a complete listing or, ideally, a Java library doing it.

    This Github project is promising but is missing a lot of geolocation information for a lot of regions.

    Note that, unlike the question Need a list of all countries in the world, with a longitude and latitude coordinate, this one refers to regional subdivisions (iso-3166-2).

    解决方案

    Since I didn't get any answers, I will explain how I solved it.

    I found this csv listing for the iso-3166-1 country code centroids: http://dev.maxmind.com/geoip/legacy/codes/country_latlon/ (I had to make a few manual tweaks)

    As for the iso-3166-2 region centroids, I ended up creating a shell script which uses the Google Maps API to print the region centroids in csv format (note that I didn't verify the full output but the cases I checked are correct). Here's a simplified version of the script using curl and jq to process the API's output:

    #!/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
    

    Then I imported the csv listings in my java code using Apache Commons CSV

    这篇关于国家/地区代码(iso-3166-1 / iso-3166-2)为经度和纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆