OpenCage Geocoder - Easy, Open, Worldwide, Affordable Geocoding
誤解を恐れずに言うと、世の中のイケてるGeocoding APIをいい感じにラップしてくれるAPIです
無料で API Key を1つ発行してくれて、2,500 req/day, 1req/sec なのでそこそこ使えます
ターミナルで簡単に呼び出すためにこんな関数を定義してみます
# あらかじめ OpenCage にサインアップして API Key を取得し環境変数に入れておきます
export CAPIKEY=<your-api-key>
# 関数定義
rg_cage(){
lon=$1
lat=$2
CURL_OPT=${CURL_OPT:--s}
# 任意キーワード: CQUERY
exec curl "$CURL_OPT" \
"https://api.opencagedata.com/geocode/v1/json?key=${CAPIKEY}&pretty=1&q=${lat},${lon}${CQUERY}"
}
広島のとある場所
$ rg_cage 133.3843445777893 34.50165844222924 | jq .results[0].components
{
"ISO_3166-1_alpha-2": "JP",
"ISO_3166-1_alpha-3": "JPN",
"_category": "building",
"_type": "building",
"city": "Fukuyama",
"continent": "Asia",
"country": "Japan",
"country_code": "jp",
"neighbourhood": "今町",
"postcode": "721-0973",
"public_building": "農業・食品産業技術総合研究機構近畿中国四国農業研究センター本所",
"road": "坪生福山線",
"state": "Hiroshima Prefecture"
}
多言語対応だそうなので、同じものをロシア語で
$ CQUERY='&language=ru' rg_cage 133.3843445777893 34.50165844222924 | jq .results[0].components
{
"ISO_3166-1_alpha-2": "JP",
"ISO_3166-1_alpha-3": "JPN",
"_category": "building",
"_type": "building",
"city": "Фукуяма",
"continent": "Asia",
"country": "Япония",
"country_code": "jp",
"neighbourhood": "今町",
"postcode": "721-0973",
"public_building": "農業・食品産業技術総合研究機構近畿中国四国農業研究センター本所",
"road": "坪生福山線",
"state": "Хиросима"
}
行政区域はロシア語化されてますね
海外ロケもやってみましょう
ヒルトン ハワイアン ビレッジ ワイキキ ビーチ リゾート ラグーン タワー付近
同じ場所をGoogle Geocodeで