中國地圖服務商為了國家測繪安全,採用不同加密偏移算法:百度用 BD-09、騰訊/Google/高德用 GCJ-02(火星坐標)、GPS 原始為 WGS-84。直接混用會導致標註偏移數十至數百米。本文對比三種轉換方案,推薦生產環境採用官方 SDK 介面保證精度。
WGS-84 (GPS 原始)
↓ 國家加密算法 (非線性偏移)
GCJ-02 (火星坐標) ←→ 高德、騰訊、Google 中國
↓ 百度二次加密
BD-09 (百度坐標) ←→ 百度地圖
⚠️ 核心結論:騰訊、高德、Google 中國共用 GCJ-02,百度獨用 BD-09。轉換本質是 BD-09 ⇄ GCJ-02 互轉。
{
"status": 0,
"message": "query ok",
"result": [
{ "lat": 39.984012, "lng": 116.307634 } // GCJ-02
]
}
// 轉換
var points = [new qq.maps.LatLng(39.984154, 116.307490)]; // BD-09
qq.maps.convertor.translate(points, 3, function(res) {
console.log(res[0].lat, res[0].lng); // GCJ-02
});
若需 GCJ-02 → BD-09,百度提供 BMap.Convertor:
用途 網址 在線坐標轉換測試 https://www.minigps.net/convert.html百度拾取坐標 https://api.map.baidu.com/lbsapi/getpoint/騰訊坐標拾取/反向地理編碼 https://lbs.qq.com/javascript_v2/case-run.html#sample-geocoding-reverse生產環境架構建議
3, 'key' => $this->qqKey ] ]); $data = json_decode($resp->getBody(), true); if ($data['status'] !== 0 || empty($data['result'])) { throw new \RuntimeException("騰訊坐標轉換失敗: " . ($data['message'] ?? 'unknown')); } $pt = $data['result'][0]; return ['lat' => $pt['lat'], 'lng' => $pt['lng']]; } // 批量轉換 (單次最多 100 對) public function batchBd09ToGcj02(array $points): array { $locStr = implode(';', array_map(fn($p) => "{$p['lat']},{$p['lng']}", $points)); $resp = $this->client->get('https://apis.map.qq.com/ws/coord/v1/translate', [ 'query' => ['locations' => $locStr, 'type' => 3, 'key' => $this->qqKey] ]); $data = json_decode($resp->getBody(), true); // ... 解析批量結果 } }關鍵決策矩陣
| 場景 | 推薦方案 | 理由 |
|---|---|---|
| 後端批量導入/清洗數據 | 騰訊 HTTP API + 批量介面 | 官方精度、支援批量、可重試、可監控 |
| 前端即時標註/用戶定位 | 騰訊 JS SDK convertor | 無需後端代理、客戶端直連、體驗流暢 |
| 百度地圖內部混合顯示 | 百度 BMap.Convertor | 同生態最優、無跨域問題 |
| 離線/嵌入式/無網環境 | 開源算法庫 + 版本鎖定 | 不可依賴網路、接受誤差、需定期驗證 |
Point(lng, lat)、騰訊 LatLng(lat, lng)、HTTP API locations=lat,lng —— 務必查閱各平台文檔坐標系轉換是 LBS 開發的基礎設施級問題。堅持「官方介面優先、算法僅作備胎」原則,配合緩存、熔斷、降級機制,才能構建穩定可靠的地理空間服務。