逆ジオコーディング
座標を入力すると最寄りの住所を返します。必要なのがそれだけなら、市区町村、地域、国を返すこともできます。
GEThttps://api.mygeocode.com/v1/reverse
パラメータ
| パラメータ | 型 | 説明 |
|---|---|---|
lat必須 | 数値 | -90から90。 |
lon必須 | 数値 | -180から180。 |
level任意 | 文字列 | 返す最も詳細なレベル:address(既定値)、street、postcode、city、region、country。粗いレベルほど高速で、要求したレベルより詳細になることはありません。 |
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 | ジオコーディングと同じです。 |
注意事項
distance_mが大きいことは1つのシグナルです。公園内の地点は最寄りの住所から300 m離れていることがあり、その場合は住所よりも周辺地域を表示する方が通常は適切です。level=countryは約1ミリ秒で応答し、「この地点はどの国にあるか」に答える最も安価な方法です。- 海上の地点は、
addressレベルではnullを返し、領海内であればcountryレベルで国を返します。
他のプロバイダーの形式での同じ検索
これらのプロバイダー向けに書いたコードがすでにある場合は、そのまま使えます。互換ホストは同じパスとパラメータを受け付け、このエンドポイントを背後に使って、そのプロバイダーのレスポンス形式で応答します。互換ホストの仕組みをご覧ください。
| プロバイダー | ホスト | パス |
|---|---|---|
| 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 Geocoding | mapbox.mygeocode.com | /geocoding/v5/mapbox.places/{lon},{lat}.json/search/geocode/v6/reverse?longitude=...&latitude=... |
| Geocode.Farm | farm.mygeocode.com | /reverse/?lat=...&lon=.../v3/json/reverse/?lat=...&lon=... |
| OpenStreetMap Nominatim | osm.mygeocode.com | /reverse?lat=...&lon=...&format=json |
| OpenCage | opencage.mygeocode.com | /geocode/v1/json?q=lat,lng |
| LocationIQ | locationiq.mygeocode.com | /v1/reverse?lat=...&lon=...&format=json |
| Geoapify | geoapify.mygeocode.com | /v1/geocode/reverse?lat=...&lon=... |
| TomTom Search | tomtom.mygeocode.com | /search/2/reverseGeocode/{lat},{lon}.json |
| MapQuest Geocoding | mapquest.mygeocode.com | /geocoding/v1/reverse?location=lat,lng |
| Geocodio | geocodio.mygeocode.com | /v1.7/reverse?q=lat,lng |
| PositionStack | positionstack.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。