
10家適合網(wǎng)站項(xiàng)目使用的最佳翻譯api平臺(tái)
點(diǎn)擊查看地圖API更多對(duì)比數(shù)據(jù)
32位字母數(shù)字組合
)。<!DOCTYPE html>
<html>
<head>
<!-- 引入天地圖JS -->
<script src="http://api.tianditu.gov.cn/api?v=4.0&tk=YOUR_KEY"></script>
</head>
<body>
<div id="map" style="width:100vw;height:90vh"></div>
<script>
// 初始化地圖
const map = new T.Map("map");
// 設(shè)置中心點(diǎn)(北京坐標(biāo))和縮放級(jí)別
map.centerAndZoom(new T.LngLat(116.40769, 39.89945), 12);
// 啟用滾輪縮放
map.enableScrollWheelZoom();
</script>
</body>
</html>
關(guān)鍵參數(shù)說明:
T.Map
:地圖容器實(shí)例化類centerAndZoom(T.LngLat, level)
:中心點(diǎn)坐標(biāo)(經(jīng)度,緯度)和縮放級(jí)別(3~18級(jí))import requests
def geocode(address, api_key):
url = f"http://api.tianditu.gov.cn/geocoder?ds={{%22keyWord%22:%22{address}%22}}&tk={api_key}"
res = requests.get(url)
data = res.json()
if data['status'] == 200:
return data['location']['lon'], data['location']['lat'] # 返回(經(jīng)度, 緯度)
else:
raise Exception(f"地理編碼失敗: {data['msg']}")
# 調(diào)用示例
lon, lat = geocode("北京市延慶區(qū)夕陽紅養(yǎng)老院", "YOUR_KEY")
print(f"坐標(biāo):{lon}, {lat}") # 輸出:116.12345, 40.67890
import requests, json
def search_poi(lon, lat, radius, keyword, api_key):
params = {
"keyWord": keyword,
"level": "15",
"mapBound": f"{lon-0.02},{lat-0.02},{lon+0.02},{lat+0.02}", # 以坐標(biāo)為中心的區(qū)域
"queryType": "2", # 周邊搜索
"count": "20",
"start": "0"
}
url = "http://www.tianditu.com/query.shtml"
res = requests.post(url, params={"type": "query", "postStr": json.dumps(params)})
return res.json()["pois"] # 返回POI列表
# 搜索坐標(biāo)周邊2km內(nèi)的銀行
banks = search_poi(116.40769, 39.89945, 2000, "銀行", "YOUR_KEY")
注意:返回的JSON數(shù)據(jù)結(jié)構(gòu)包含name
(名稱)、address
(地址)、lon/lat
(坐標(biāo))等字段。
天地圖API并非完全免費(fèi),其配額規(guī)則如下:
限制類型 | 免費(fèi)額度 | 超出后處理 |
非商業(yè)用途 | 10,000次/日 | 需購買商用套餐 |
衛(wèi)星影像調(diào)用 | 5,000次/日 | 按量計(jì)費(fèi)(0.1元/次) |
高并發(fā)請(qǐng)求(>50QPS) | 需申請(qǐng) | 自動(dòng)攔截418錯(cuò)誤 |
const keys = ["KEY1", "KEY2", "KEY3"];
const randomKey = keys[Math.floor(Math.random() * keys.length)];
const server = t${Math.floor(Math.random() * 8)}.tianditu.gov.cn
;
const tileURL = http://${server}/img_w/wmts?SERVICE=WMTS&...&tk=${randomKey}
;
// 創(chuàng)建矢量底圖圖層
const vecLayer = new T.TileLayer("http://t0.tianditu.gov.cn/vec_c/wmts?...");
// 創(chuàng)建影像底圖圖層
const imgLayer = new T.TileLayer("http://t0.tianditu.gov.cn/img_c/wmts?...");
// 疊加顯示
map.addLayer(vecLayer);
map.addLayer(imgLayer);
tk
參數(shù)至請(qǐng)求URL。天地圖API作為國產(chǎn)GIS服務(wù)的核心基礎(chǔ)設(shè)施,在數(shù)據(jù)權(quán)威性和本地化支持上具備獨(dú)特優(yōu)勢。開發(fā)者需重點(diǎn)關(guān)注:密鑰安全管控、配額動(dòng)態(tài)監(jiān)測、服務(wù)域名負(fù)載均衡三大技術(shù)要點(diǎn)。隨著2024年新一代地理信息平臺(tái)的建設(shè),其三維實(shí)景地圖、實(shí)時(shí)路徑規(guī)劃等新功能將逐步開放,值得持續(xù)關(guān)注技術(shù)演進(jìn)。
相關(guān)文章推薦:
10家適合網(wǎng)站項(xiàng)目使用的最佳翻譯api平臺(tái)
Transformers Generate 功能介紹
使用Rust構(gòu)建高性能REST API
使用 FastAPI 和 RabbitMQ 構(gòu)建端到端微服務(wù):綜合指南
Yahoo Finance API – 完整指南
WordPress REST API 內(nèi)容注入漏洞分析
四款A(yù)I大模型API價(jià)格對(duì)比:DeepSeek R1、ChatGPT o3-mini、Grok3、通義千問 Max
四款A(yù)I大模型API基礎(chǔ)參數(shù)、核心性能的區(qū)別:DeepSeek R1、ChatGPT o3-mini、Grok3、通義千問 Max
2025年多模態(tài)大模型API基礎(chǔ)參數(shù)、核心性能:Deepseek、ChatGPT、文心一言
對(duì)比大模型API的內(nèi)容創(chuàng)意新穎性、情感共鳴力、商業(yè)轉(zhuǎn)化潛力
一鍵對(duì)比試用API 限時(shí)免費(fèi)