地图技能
使用免费开源数据源的位置智能工具。包含8个命令、44个POI类别,零依赖(仅使用Python标准库),无需API密钥。
数据源:OpenStreetMap/Nominatim、Overpass API、OSRM、TimeAPI.io。
该技能取代了旧的find-nearby技能——find-nearby的所有功能均由下面的nearby命令覆盖,并保持相同的--near "<地点>"快捷方式和多类别支持。
使用场景
- 用户发送Telegram位置定位(消息中包含纬度/经度)→
nearby - 用户想要地名的坐标 →
search - 用户有坐标,想要地址 →
reverse - 用户询问附近的餐馆、医院、药店、酒店等 →
nearby - 用户想要驾车/步行/骑行的距离或行程时间 →
distance - 用户想要两地之间的逐向导航 →
directions - 用户想要某个位置的时区信息 →
timezone - 用户想要在一个地理区域内搜索POI →
area+bbox
前提条件
Python 3.8+(仅stdlib —— 无需pip安装)。
脚本路径:~/.hermes/skills/maps/scripts/maps_client.py
命令
MAPS=~/.hermes/skills/maps/scripts/maps_client.py
search —— 将地名转换为地理编码
python3 $MAPS search "埃菲尔铁塔"
python3 $MAPS search "1600 Pennsylvania Ave, Washington DC"
返回:纬度,经度,显示名称,类型,边界框,重要度分数。
reverse —— 坐标转地址
python3 $MAPS reverse 48.8584 2.2945
返回:完整的地址分解(街道、城市、州、国家、邮政编码)。
nearby —— 按类别查找附近地点
# 按坐标(例如来自Telegram位置定位)
python3 $MAPS nearby 48.8584 2.2945 restaurant --limit 10
python3 $MAPS nearby 40.7128 -74.0060 hospital --radius 2000
# 按地址/城市/邮编/地标 —— `--near` 自动进行地理编码
python3 $MAPS nearby --near "时代广场, 纽约" --category cafe
python3 $MAPS nearby --near "90210" --category pharmacy
# 多个类别合并为一次查询
python3 $MAPS nearby --near "downtown austin" --category restaurant --category bar --limit 10
46个类别:restaurant, cafe, bar, hospital, pharmacy, hotel, guest_house, camp_site, supermarket, atm, gas_station, parking, museum, park, school, university, bank, police, fire_station, library, airport, train_station, bus_stop, church, mosque, synagogue, dentist, doctor, cinema, theatre, gym, swimming_pool, post_office, convenience_store, bakery, bookshop, laundry, car_wash, car_rental, bicycle_rental, taxi, veterinary, zoo, playground, stadium, nightclub。
每个结果包含:name、address、lat/lon、distance_m、maps_url(可点击的谷歌地图链接)、directions_url(从搜索点出发的谷歌地图导航链接),以及可用的推广标签——cuisine、hours(营业时间)、phone、website。
distance —— 旅行距离与时间
python3 $MAPS distance "巴黎" --to "里昂"
python3 $MAPS distance "纽约" --to "波士顿" --mode driving
python3 $MAPS distance "大本钟" --to "塔桥" --mode walking
模式:driving(默认)、walking、cycling。返回道路距离、行驶时间以及用于比较的直线距离。
directions —— 逐向导航
python3 $MAPS directions "埃菲尔铁塔" --to "卢浮宫博物馆" --mode walking
python3 $MAPS directions "肯尼迪机场" --to "时代广场" --mode driving
返回带编号的步骤,包含指令、距离、持续时间、道路名称和操作类型(转弯、出发、到达等)。
timezone —— 坐标的时区
python3 $MAPS timezone 48.8584 2.2945
python3 $MAPS timezone 35.6762 139.6503
返回时区名称、UTC偏移量和当前当地时间。
area —— 地点的边界框和区域
python3 $MAPS area "曼哈顿, 纽约"
python3 $MAPS area "伦敦"
返回边界框坐标、宽度/高度(公里)和近似面积。可用作bbox命令的输入。
bbox —— 在边界框内搜索
python3 $MAPS bbox 40.75 -74.00 40.77 -73.98 restaurant --limit 20
在一个地理矩形内查找POI。先使用area获取命名地点的边界框坐标。
使用Telegram位置定位
当用户发送位置定位时,消息中包含latitude:和longitude:字段。提取这些字段并直接传递给nearby:
# 用户在36.17、-115.14发送了一个定位点,并要求“查找附近的咖啡馆”
python3 $MAPS nearby 36.17 -115.14 cafe --radius 1500
将结果以编号列表形式呈现,包含名称、距离和maps_url字段,以便用户在聊天中获得点击即打开的链接。对于“现在营业吗?”的问题,请检查hours字段;如果缺失或不明确,请使用web_search进行验证,因为OSM的营业时间由社区维护,不保证始终是最新的。
工作流示例
“在罗马斗兽场附近找意大利餐馆”:
nearby --near "Colosseum Rome" --category restaurant --radius 500— 一条命令,自动地理编码
“他们发送的这个位置定位附近有什么?”:
- 从Telegram消息中提取纬度/经度
nearby LAT LON cafe --radius 1500
“从酒店走到会议中心怎么走?”:
directions "酒店名称" --to "会议中心" --mode walking
“西雅图市中心有哪些餐馆?”:
area "西雅图市中心"→ 获取边界框bbox S W N E restaurant --limit 30
注意事项
- Nominatim服务条款:最大请求频率为1次/秒(脚本已自动处理)
nearby需要提供经纬度或--near "<地址>"—— 两者必须提供其一- OSRM路由覆盖范围在欧洲和北美最佳
- Overpass API在高峰时段可能较慢;脚本会在镜像之间自动回退(overpass-api.de → overpass.kumi.systems)
distance和directions使用--to参数指定目的地(非位置参数)- 如果仅使用邮政编码在全球范围内产生歧义,请包含国家/州信息
验证
python3 ~/.hermes/skills/maps/scripts/maps_client.py search "自由女神像"
# 应返回纬度约40.689,经度约-74.044
python3 ~/.hermes/skills/maps/scripts/maps_client.py nearby --near "时代广场" --category restaurant --limit 3
# 应返回时代广场周围约500米范围内的餐馆列表