共享 API 文档
逆地理解析
把用户选点或定位坐标换成可展示的地址。
把 GCJ02 经纬度解析成国家、省、市、区、街道、门牌与格式化地址。
鉴权:浏览器 / WebView 可用来源域放行;服务端、小程序、APP 用应用放行(X-App-Id + X-App-Token)。下方示例按服务端应用放行给出,接口不涉及用户身份,不需要用户 token。
| 字段 | 类型 | 必填 | 取值 | 说明 |
|---|---|---|---|---|
lng |
float | 是 | GCJ02 经度 | 超出中国范围返回 10001 |
lat |
float | 是 | GCJ02 纬度 | 同上 |
provider |
string | 否 | tianditu / tencent |
默认 tianditu |
get_poi |
int | 否 | 0 / 1 |
是否返回周边 POI,默认 0 |
poi_options |
string | 否 | 字符串 | 仅 tencent 通道有效 |
{ "code": 0, "msg": "请求成功", "data": { "status": 0, "message": "query ok", "result": { "address": "青年路416正西方向130米", "formatted_addresses": { "recommend": "云南省昆明市五华区护国街道停车场" }, "address_component": { "province": "云南省", "city": "昆明市", "district": "五华区", "township": "护国街道" }, "location": { "lng": 102.712251, "lat": 25.040609 } } } }
- 响应先判断
code === 0,再读data.result;授权失败的错误体没有result。 - 坐标必须是 GCJ02;GPS 原始坐标先转换再传。
get_poi=1时才会返回周边 POI,不需要就不要打开,响应体会小很多。
调用示例
curl -sS -X POST "https://api.micro.lck.yn.cn/map/geocode" \ -H "Content-Type: application/json" \
-H "X-App-Id: $APP_ID" \
-H "X-App-Token: $APP_TOKEN" \
-d '{"lng":102.712251,"lat":25.040609,"provider":"tianditu","get_poi":0,"poi_options":""}'<?php
$body = '{"lng":102.712251,"lat":25.040609,"provider":"tianditu","get_poi":0,"poi_options":""}';
$headers = [
'Content-Type: application/json',
'X-App-Id: ' . getenv('APP_ID'),
'X-App-Token: ' . getenv('APP_TOKEN'),
];
$ctx = stream_context_create(['http' => [
'method' => 'POST',
'header' => implode("\r\n", $headers) . "\r\n",
'content' => $body,
'timeout' => 10,
]]);
$resp = file_get_contents('https://api.micro.lck.yn.cn/map/geocode', false, $ctx);
if ($resp === false) { fwrite(STDERR, "request failed\n"); exit(1); }
echo $resp, PHP_EOL;const res = await fetch('https://api.micro.lck.yn.cn/map/geocode', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-App-Id': process.env.APP_ID,
'X-App-Token': process.env.APP_TOKEN,
},
body: '{"lng":102.712251,"lat":25.040609,"provider":"tianditu","get_poi":0,"poi_options":""}'
});
if (!res.ok) throw new Error('HTTP ' + res.status);
console.log(await res.text());import os, urllib.request
req = urllib.request.Request(
'https://api.micro.lck.yn.cn/map/geocode',
data='{"lng":102.712251,"lat":25.040609,"provider":"tianditu","get_poi":0,"poi_options":""}'.encode('utf-8'),
headers={
'Content-Type': 'application/json',
'X-App-Id': os.environ['APP_ID'],
'X-App-Token': os.environ['APP_TOKEN'],
},
method='POST',
)
with urllib.request.urlopen(req, timeout=10) as resp:
print(resp.read().decode('utf-8'))package main
import (
"fmt"
"io"
"net/http"
"strings"
"os"
)
func main() {
req, err := http.NewRequest("POST", "https://api.micro.lck.yn.cn/map/geocode", strings.NewReader(`{"lng":102.712251,"lat":25.040609,"provider":"tianditu","get_poi":0,"poi_options":""}`))
if err != nil { panic(err) }
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-App-Id", os.Getenv("APP_ID"))
req.Header.Set("X-App-Token", os.Getenv("APP_TOKEN"))
resp, err := http.DefaultClient.Do(req)
if err != nil { panic(err) }
defer resp.Body.Close()
data, _ := io.ReadAll(resp.Body)
fmt.Println(string(data))
}import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Demo {
public static void main(String[] args) throws Exception {
HttpRequest req = HttpRequest.newBuilder(URI.create("https://api.micro.lck.yn.cn/map/geocode"))
.header("Content-Type", "application/json")
.header("X-App-Id", System.getenv("APP_ID"))
.header("X-App-Token", System.getenv("APP_TOKEN"))
.POST(HttpRequest.BodyPublishers.ofString("{\"lng\":102.712251,\"lat\":25.040609,\"provider\":\"tianditu\",\"get_poi\":0,\"poi_options\":\"\"}"))
.build();
HttpResponse<String> res = HttpClient.newHttpClient()
.send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(res.body());
}
}// 安全:appId 由平台下发;appToken 由你方服务端换取并缓存中转,
// 不要写进小程序代码,AppSecret 更不能放前端。
const APP_ID = '(由你方服务端下发,勿硬编码)'
const APP_TOKEN = '(由你方服务端换取并缓存,勿下发前端)'
wx.request({
url: 'https://api.micro.lck.yn.cn/map/geocode',
method: 'POST',
data: {"lng":102.712251,"lat":25.040609,"provider":"tianditu","get_poi":0,"poi_options":""},
header: {
'content-type': 'application/json',
'X-App-Id': APP_ID,
'X-App-Token': APP_TOKEN
},
success(res) { console.log(res.data) },
fail(err) { console.error(err) }
})// Flutter:pubspec.yaml 加 http 依赖。
// 安全:appId/appToken 由你方服务端下发并缓存中转,不要硬编码在 APP 包体内。
const appIdFromServer = '由服务端注入' // 勿硬编码
const tokenFromServer = '由服务端换取并缓存' // 勿下发前端
import 'package:http/http.dart' as http;
Future<void> main() async {
final res = await http.post(
Uri.parse('https://api.micro.lck.yn.cn/map/geocode'),
headers: {
'Content-Type': 'application/json',
'X-App-Id': appIdFromServer,
'X-App-Token': tokenFromServer,
},
body: r'{"lng":102.712251,"lat":25.040609,"provider":"tianditu","get_poi":0,"poi_options":""}',
);
print(res.body);
}