逆ジオコーディング

座標を入力すると最寄りの住所を返します。必要なのがそれだけなら、市区町村、地域、国を返すこともできます。

GEThttps://api.mygeocode.com/v1/reverse

パラメータ

パラメータ説明
lat必須数値-90から90。
lon必須数値-180から180。
level任意文字列返す最も詳細なレベル:address(既定値)、streetpostcodecityregioncountry。粗いレベルほど高速で、要求したレベルより詳細になることはありません。
radius任意整数住所の検索半径(メートル)、1から5000。既定値は5000。遠く離れた住所ではなくnullを得たい場合は小さく設定してください。
lang任意文字列名前に使うISO 639-1コード。既定値はen
key任意文字列ヘッダーで送信しない場合のAPIキー。

$ curl -H "X-API-Key: YOUR_KEY" "https://api.mygeocode.com/v1/reverse?lat=41.8902&lon=12.4922&lang=it"
const url = new URL("https://api.mygeocode.com/v1/reverse");
url.searchParams.set("lat", 41.8902);
url.searchParams.set("lon", 12.4922);
url.searchParams.set("lang", "it");

const { result } = await (await fetch(url, { headers: { "X-API-Key": "YOUR_KEY" } })).json();
console.log(result ? result.formatted : "nothing nearby");
import requests

r = requests.get("https://api.mygeocode.com/v1/reverse",
                 params={"lat": 41.8902, "lon": 12.4922, "lang": "it"}, headers={"X-API-Key": "YOUR_KEY"}, timeout=10)
result = r.json()["result"]
print(result["formatted"] if result else "nothing nearby")
レスポンス
{
  "status": "ok",
  "lat": 41.8902,
  "lon": 12.4922,
  "result": {
    "formatted": "Piazza del Colosseo 1, 00184 Roma RM, Italia",
    "lat": 41.890251,
    "lon": 12.492373,
    "distance_m": 9,
    "type": "address",
    "precision": "house",
    "place_id": "it.addr.5d09aa31",
    "components": {
      "house_number": "1",
      "road": "Piazza del Colosseo",
      "suburb": "Municipio Roma I",
      "city": "Roma",
      "county": "Roma",
      "state": "Lazio",
      "postcode": "00184",
      "country": "Italia",
      "country_code": "it"
    }
  }
}

レスポンスフィールド

フィールド説明
lat, lon数値送信した地点をそのまま返したもの。
resultオブジェクトまたはnull要求したレベルでradius内に何もない場合はnull
result.formatted文字列住所。粗いレベルでは地名。
result.lat, result.lon数値返された地物の位置(送信した地点ではありません)。
result.distance_m整数送信した地点から地物までの距離(メートル)。地点が地物の内部にある場合は0。
result.type, result.precision, result.place_id, result.componentsジオコーディングと同じです。

注意事項

他のプロバイダーの形式での同じ検索

これらのプロバイダー向けに書いたコードがすでにある場合は、そのまま使えます。互換ホストは同じパスとパラメータを受け付け、このエンドポイントを背後に使って、そのプロバイダーのレスポンス形式で応答します。互換ホストの仕組みをご覧ください。

プロバイダーホストパス
Googleマップ・プラットフォーム(Google Maps Platform)gapi.mygeocode.com/maps/api/geocode/json?latlng=lat,lng
Bing Maps RESTサービスbing.mygeocode.com/REST/v1/Locations/{lat},{lon}
HEREジオコーディング・検索(HERE Geocoding and Search)here.mygeocode.com/v1/revgeocode?at=lat,lng
Mapbox Geocodingmapbox.mygeocode.com/geocoding/v5/mapbox.places/{lon},{lat}.json
/search/geocode/v6/reverse?longitude=...&latitude=...
Geocode.Farmfarm.mygeocode.com/reverse/?lat=...&lon=...
/v3/json/reverse/?lat=...&lon=...
OpenStreetMap Nominatimosm.mygeocode.com/reverse?lat=...&lon=...&format=json
OpenCageopencage.mygeocode.com/geocode/v1/json?q=lat,lng
LocationIQlocationiq.mygeocode.com/v1/reverse?lat=...&lon=...&format=json
Geoapifygeoapify.mygeocode.com/v1/geocode/reverse?lat=...&lon=...
TomTom Searchtomtom.mygeocode.com/search/2/reverseGeocode/{lat},{lon}.json
MapQuest Geocodingmapquest.mygeocode.com/geocoding/v1/reverse?location=lat,lng
Geocodiogeocodio.mygeocode.com/v1.7/reverse?q=lat,lng
PositionStackpositionstack.mygeocode.com/v1/reverse?query=lat,lng

一括検索

同じパスに、最大100組の[lat, lon]の配列であるcoordsを含むJSON本文をPOSTすると、応答には送信した順序どおりに組ごとに1エントリを持つresults配列が含まれます。各エントリが1件のリクエストとして数えられ、割り当ての残りを超える一括処理は全体が拒否されます。

$ curl -X POST "https://api.mygeocode.com/v1/reverse" -H "Content-Type: application/json" -d '{"coords": [[52.5163, 13.3777], [47.3769, 8.5417]]}'

エラー

latまたはlonがないか範囲外の場合、またはlevelが一覧の値のいずれでもない場合は400 invalid_request