Country / Region Code (ISO-3166-1 / ISO-3166-2) for longitude and latitude

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

Examples:

  • Entrance: "USA", exit: (37.09024, -95.71289100000001).
  • Input "VE-O", output: (10.9970723, -63.91132959999999).

I searched, but could not find a complete list, or, ideally, a Java library that runs it.

This Github project is promising, but lacks a lot of geolocation information for many regions.

Please note that unlike the question, you need to make a list of all countries of the world with the coordinate of longitude and latitude , this applies to regional units (iso-3166 -2).

+1
java geolocation geocoding
Mar 01 '15 at 13:48
source share
2 answers

Since I had no answers, I will explain how I solved it.

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

Regarding the centroids of the iso-3166-2 area, I ended up creating a shell script that uses the Google Maps API to print the region centroids in csv format (note that I did not check the full output, but the cases that I checked are correct). Here's a simplified version of the script using curl and jq to handle API 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 lists into my Java code using Apache Commons CSV

+1
Jun 02 '15 at 12:01
source share

These are the best resources that I found when I had to solve this problem:

Country coordinates: http://dev.maxmind.com/geoip/legacy/codes/country_latlon/

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

0
Jul 19 '16 at 21:14
source share



All Articles