逆地理编码
输入坐标,返回最近的地址;如果您只需要这些,也可以返回所在的地方、地区或国家。
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是一个信号。公园里的一个点可能距离最近的地址 300 米;这种情况下,显示所在街区通常比显示地址更好。 level=country大约一毫秒即可返回,是回答“这个点在哪个国家”最便宜的方式。- 海上的点在
address级别返回null;在领海范围内,country级别返回所属国家。
以其他服务商格式进行的同一查询
如果您已有针对这些服务商之一编写的代码,请保留它:兼容替换主机接受相同的路径和参数,并以该服务商的响应结构作答,背后由此端点提供支持。请参阅兼容替换主机的工作原理。
| 服务商 | 主机 | 路径 |
|---|---|---|
| Google Maps 平台 | gapi.mygeocode.com | /maps/api/geocode/json?latlng=lat,lng |
| Bing Maps REST 服务 | bing.mygeocode.com | /REST/v1/Locations/{lat},{lon} |
| HERE 地理编码与搜索 | 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 |
批量查询
向同一路径 POST 一个 JSON 正文,其中 coords 是最多包含 100 个 [lat, lon] 坐标对的数组,响应会带有一个 results 数组,按发送顺序每个坐标对对应一条记录。每条记录计为一次请求,超出剩余配额的批量请求会被整体拒绝。
$ 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。