用于在中国地图服务(百度、高德、谷歌中国等)之间进行坐标转换,支持 WGS84、GCJ02、BD09、BD09MC 或 WebMercator 坐标系之间的相互转换。
处理中国互联网地图坐标系不统一的问题,支持 WGS84/GCJ02/BD09/BD09MC/WebMercator 等坐标系之间的精确转换。
dot
digraph gcoord_flow {
"Need to convert coordinates?" [shape=diamond];
"Using Chinese map service?" [shape=diamond];
"Use this skill" [shape=box];
"Use standard tools" [shape=box];
"Need to convert coordinates?" -> "Using Chinese map service?" [label="yes"];
"Using Chinese map service?" -> "Use this skill" [label="yes"];
"Using Chinese map service?" -> "Use standard tools" [label="no"];
}
Use when:
代码中文名称别名适用平台WGS84地球坐标系GPS, wgs84, 地球坐标GPS 设备原始坐标GCJ02火星坐标系高德, amap, 腾讯, gcj02, 火星坐标高德地图、腾讯地图BD09百度坐标系百度, baidu, bd09百度地图BD09MC百度米制坐标bd09mc, 百度米制百度地图米制WebMercator墨卡托投影墨卡托, webmercator, epsg3857Web 地图投影
格式示例说明坐标数组[116.403988, 39.914266]JSON 数组格式单点坐标116.403988, 39.914266逗号或空格分隔GeoJSON{ "type": "Point", "coordinates": [...] }完整 GeoJSON 对象批量文本每行一个坐标多行文本处理
输出格式默认与输入格式相同。
text
/gcoord [坐标] --from [源坐标系] --to [目标坐标系]
# 示例
/gcoord 116.403988,39.914266 --from wgs84 --to bd09
/gcoord [116.403988, 39.914266] from gps to 百度
text
"帮我把这个坐标转换成高德坐标系"
"GPS 坐标转百度地图"
"WGS84 转 GCJ02"
text
# Missing parameters - Claude will prompt
"帮我转换坐标 116.403988,39.914266"
→ Claude prompts for source and target coordinate systems
# Clear target from context
"把 116.403988,39.914266 在百度地图上显示"
→ Claude only asks for source (target is clearly BD09)
# Explicit parameters - no prompts
/gcoord 116.403988,39.914266 --from WGS84 --to BD09
→ Direct conversion, no questions asked
在使用 AskUserQuestion 工具前,先尝试从用户输入中推断坐标系。只有在无法推断时才询问:
优先级判断:
--from, --to)*-gcj02.geojson、前文对话)当需要询问坐标系时,使用以下格式:
源坐标系询问:
text
AskUserQuestion({
questions: [{
question: "请选择源坐标系(您当前的坐标使用什么坐标系?)",
header: "源坐标系",
multiSelect: false,
options: [
{
label: "WGS84 (GPS)",
description: "GPS 设备原始坐标,地球坐标"
},
{
label: "GCJ02 (高德/腾讯)",
description: "高德地图、腾讯地图坐标系"
},
{
label: "BD09 (百度)",
description: "百度地图坐标系"
},
{
label: "BD09MC (百度米制)",
description: "百度地图米制坐标"
},
{
label: "WebMercator (墨卡托)",
description: "Web 地图投影坐标"
}
]
}]
})
目标坐标系询问:
在询问前,检查用户是否通过自然语言指定了坐标系:
源坐标系关键词:
目标坐标系关键词:
场景 1: 完全未指定
text
用户: 帮我转换 116.403988,39.914266
Claude:
1. 无法从输入推断源和目标坐标系
2. 询问源坐标系 → 用户选择: WGS84
3. 询问目标坐标系 → 用户选择: GCJ02
4. 调用: node index.js --input "116.403988,39.914266" --from WGS84 --to GCJ02
场景 2: 仅指定目标
text
用户: 把 116.403988,39.914266 在百度地图上显示
Claude:
1. 从上下文推断: 目标 = BD09 (明确)
2. 源坐标系不明确 → 询问用户
3. 用户选择: WGS84
4. 调用: node index.js --input "116.403988,39.914266" --from WGS84 --to BD09
场景 3: 明确指定(不询问)
text
用户: GPS转高德: 116.403988,39.914266
Claude:
1. 从自然语言识别: 源=WGS84, 目标=GCJ02
2. 直接调用: node index.js --input "116.403988,39.914266" --from WGS84 --to GCJ02
对于精确转换,使用 index.js 脚本调用 gcoord 库:
bash
node index.js --input "[116.403988, 39.914266]" --from WGS84 --to BD09
错误正确做法GPS 坐标直接放百度地图先转为 BD09 坐标系混淆经度纬度顺序始终是 [经度, 纬度]忘记 GeoJSON 是原地修改转换后原始对象会改变
使用时请遵守《中华人民共和国测绘法》和 GB 20263―2006 标准。