OpenCage 兼容替换
OpenCage 使用同一个端点进行正向和逆地理编码,并返回丰富的注释(annotations)块。opencage.mygeocode.com 也是如此,包括 OpenCage 用户会读取的时区、货币、国际电话区号、日照和位置编码注释。
只需更换一个主机名
| 原始主机 |
|
|---|---|
| 改用 | opencage.mygeocode.com |
| 密钥参数 | key(可选:任何地址不使用密钥每天也有 2,500 次请求;如需使用额度、套餐和使用记录,请在此填入您的 My Geocode 密钥) |
之前
curl "https://api.opencagedata.com/geocode/v1/json?q=Colosseum+Rome&key=YOUR_OPENCAGE_KEY"之后
curl "https://opencage.mygeocode.com/geocode/v1/json?q=Colosseum+Rome&key=YOUR_MYGEOCODE_KEY"端点
响应示例
这是上述请求返回的内容。字段名、嵌套和类型与 OpenCage 一致。只有背后的数据来自我们。
来自 opencage.mygeocode.com 的响应
{
"documentation": "https://www.mygeocode.com/compatibility/opencage/",
"licenses": [
{
"name": "My Geocode Terms",
"url": "https://www.mygeocode.com/terms/"
}
],
"rate": {
"limit": 2500,
"remaining": 2479,
"reset": 1791158400
},
"results": [
{
"annotations": {
"DMS": {
"lat": "41° 53' 24.64656'' N",
"lng": "12° 29' 32.31204'' E"
},
"H3": null,
"MGRS": "33TTG9195440624",
"Maidenhead": "JN61fv93bp",
"Mercator": {
"x": 1390637.466,
"y": 5116005.188
},
"NUTS": {
"NUTS0": {
"code": "IT"
},
"NUTS1": {
"code": "ITI"
},
"NUTS2": {
"code": "ITI4"
},
"NUTS3": {
"code": "ITI43"
}
},
"OSM": {
"note_url": "https://www.openstreetmap.org/note/new#map=16/41.89018/12.49231&layers=N",
"url": "https://www.openstreetmap.org/?mlat=41.89018&mlon=12.49231#map=16/41.89018/12.49231"
},
"UN_M49": {
"regions": {
"EUROPE": "150",
"IT": "380",
"SOUTHERN_EUROPE": "039",
"WORLD": "001"
},
"statistical_groupings": ["MEDC"]
},
"callingcode": 39,
"currency": {
"alternate_symbols": [],
"decimal_mark": ",",
"html_entity": "€",
"iso_code": "EUR",
"iso_numeric": "978",
"name": "Euro",
"smallest_denomination": 1,
"subunit": "Cent",
"subunit_to_unit": 100,
"symbol": "€",
"symbol_first": 1,
"thousands_separator": "."
},
"flag": "🇮🇹",
"geohash": "sr2yk3begzkwszr7rp57",
"qibla": 123.25,
"roadinfo": {
"drive_on": "right",
"speed_in": "km/h"
},
"sun": {
"rise": {
"apparent": 1791090610,
"astronomical": 1791085058,
"civil": 1791088947,
"nautical": 1791087011
},
"set": {
"apparent": 1791132439,
"astronomical": 1791137991,
"civil": 1791134102,
"nautical": 1791136038
}
},
"timezone": {
"name": "Europe/Rome",
"now_in_dst": 1,
"offset_sec": 7200,
"offset_string": "+0200",
"short_name": "CEST"
},
"what3words": null
},
"bounds": { "northeast": { "lat": 41.8921795, "lng": 12.4943109 }, "southwest": { "lat": 41.8881809, "lng": 12.4903121 } },
"components": {
"ISO_3166-1_alpha-2": "IT",
"ISO_3166-1_alpha-3": "ITA",
"_category": "poi",
"_normalized_city": "Rome",
"_type": "attraction",
"attraction": "Colosseum",
"city": "Rome",
"country": "Italy",
"country_code": "it",
"county": "Città metropolitana di Roma Capitale",
"state": "Lazio"
},
"confidence": 10,
"formatted": "Colosseum, Rome, Lazio, Italy",
"geometry": {
"lat": 41.8901796,
"lng": 12.4923089
}
}
],
"status": {
"code": 200,
"message": "OK"
},
"stay_informed": {
"blog": "https://www.mygeocode.com/blog/"
},
"thanks": "For using My Geocode",
"timestamp": {
"created_http": "Sun, 04 Oct 2026 07:35:02 GMT",
"created_unix": 1791099302
},
"total_results": 3
}细节与差异
每天前 2,500 次请求无需密钥。如需使用 My Geocode 密钥,请将其放在原来 OpenCage 密钥的位置:key 查询参数。X-API-Key 请求头、Authorization: Bearer 和 HTTP Basic 认证(以密钥作为用户名)也适用于每个主机,因此以自有方式进行认证的客户端库无需任何修改即可继续工作。
响应中的版权声明、许可名称、条款和隐私链接是我们的,而不是原服务商的。其他所有内容都保持原有结构。
rate信息块报告您真实的免费配额、剩余量以及重置时间。json和geojson端点均受支持。- 没有批量端点,因为原服务也没有。批量处理请使用
api.mygeocode.com上的POST /v1/forward或/v1/reverse(每次调用最多 100 条,每条计为一个请求)。 - 与 OpenCage 一样,除非您发送
no_annotations=1,否则注释默认开启:DMS、MGRS、Maidenhead、Mercator、ITM(爱尔兰)、FIPS(美国各州)、callingcode、currency、flag、geohash、qibla、roadinfo(靠道路哪一侧行驶及速度单位)、sun、timezone,以及已知时的 wikidata。what3words和H3会出现,但始终为null,因为两者都无法从开放数据来源获得。 /geocode/v1/xml以 OpenCage 的 XML 格式返回。- 在我们有相应数据的地方,会填写 NUTS(欧盟地区)、UN_M49、OSM 链接、附带县的 FIPS、
LOCODE:查询的 UN/LOCODE 以及印度的 DIGIPIN。roadinfo=1会添加来自 OpenStreetMap 的道路限速、单行道和隧道标志。
如果您的客户端依赖于此处未列出的字段或行为,请告诉我们。兼容性缺口通常很小,因此会很快修复。