101 lines
3.4 KiB
TypeScript
101 lines
3.4 KiB
TypeScript
/**
|
|
* 腾讯地图 API 测试脚本
|
|
* 运行: node scripts/test-tencent-map.ts
|
|
*/
|
|
|
|
import { searchPoi, searchNearbyPoi, searchMuseumEntrance, getMuseumEntranceLocation } from '../src/services/tencent/TencentMapService'
|
|
|
|
async function test() {
|
|
console.log('=== 测试腾讯地图 API ===\n')
|
|
|
|
// 1. 测试搜索深圳自然博物馆
|
|
console.log('1. 搜索"深圳自然博物馆"...')
|
|
const museumResult = await searchPoi('深圳自然博物馆', '深圳市', 1, 5)
|
|
console.log('状态:', museumResult.status)
|
|
console.log('消息:', museumResult.message)
|
|
console.log('结果数量:', museumResult.count)
|
|
if (museumResult.data.length > 0) {
|
|
console.log('第一个结果:')
|
|
console.log(' - ID:', museumResult.data[0].id)
|
|
console.log(' - 名称:', museumResult.data[0].title)
|
|
console.log(' - 地址:', museumResult.data[0].address)
|
|
console.log(' - 类别:', museumResult.data[0].category)
|
|
console.log(' - 坐标:', museumResult.data[0].location)
|
|
}
|
|
console.log()
|
|
|
|
if (museumResult.data.length > 0) {
|
|
const museum = museumResult.data[0]
|
|
|
|
// 2. 测试周边搜索 - 入口
|
|
console.log('2. 搜索周边"入口"...')
|
|
const entranceResult = await searchNearbyPoi(
|
|
museum.location.lat,
|
|
museum.location.lng,
|
|
'入口',
|
|
500
|
|
)
|
|
console.log('状态:', entranceResult.status)
|
|
console.log('结果数量:', entranceResult.count)
|
|
if (entranceResult.data.length > 0) {
|
|
console.log('入口结果:')
|
|
entranceResult.data.slice(0, 3).forEach((item, index) => {
|
|
console.log(` [${index + 1}] ${item.title}`)
|
|
console.log(` 地址: ${item.address}`)
|
|
console.log(` 距离: ${item.distance}米`)
|
|
console.log(` 坐标: (${item.location.lat}, ${item.location.lng})`)
|
|
})
|
|
}
|
|
console.log()
|
|
|
|
// 3. 测试周边搜索 - 出入口
|
|
console.log('3. 搜索周边"出入口"...')
|
|
const exitResult = await searchNearbyPoi(
|
|
museum.location.lat,
|
|
museum.location.lng,
|
|
'出入口',
|
|
500
|
|
)
|
|
console.log('状态:', exitResult.status)
|
|
console.log('结果数量:', exitResult.count)
|
|
if (exitResult.data.length > 0) {
|
|
console.log('出入口结果:')
|
|
exitResult.data.slice(0, 3).forEach((item, index) => {
|
|
console.log(` [${index + 1}] ${item.title}`)
|
|
console.log(` 地址: ${item.address}`)
|
|
console.log(` 距离: ${item.distance}米`)
|
|
console.log(` 坐标: (${item.location.lat}, ${item.location.lng})`)
|
|
})
|
|
}
|
|
console.log()
|
|
}
|
|
|
|
// 4. 测试完整流程
|
|
console.log('4. 测试 searchMuseumEntrance()...')
|
|
const entrance = await searchMuseumEntrance()
|
|
if (entrance) {
|
|
console.log('找到入口:')
|
|
console.log(' - 名称:', entrance.title)
|
|
console.log(' - 地址:', entrance.address)
|
|
console.log(' - 类别:', entrance.category)
|
|
console.log(' - 距离:', entrance.distance ? `${entrance.distance}米` : 'N/A')
|
|
console.log(' - 坐标:', entrance.location)
|
|
} else {
|
|
console.log('未找到入口')
|
|
}
|
|
console.log()
|
|
|
|
// 5. 测试获取入口坐标
|
|
console.log('5. 测试 getMuseumEntranceLocation()...')
|
|
const location = await getMuseumEntranceLocation()
|
|
if (location) {
|
|
console.log('入口坐标:', location)
|
|
} else {
|
|
console.log('未获取到入口坐标')
|
|
}
|
|
|
|
console.log('\n=== 测试完成 ===')
|
|
}
|
|
|
|
test().catch(console.error)
|