Appearance
概述
前面的课程中,专门学习过 高德API 如何使用,通过 高德API 的 路径规划2.0 的接口,可以获取到运动轨迹的经纬度坐标点集合,这样就可以方便的与Cesium结合使用。
路径规划2.0:https://lbs.amap.com/api/webservice/guide/api/newroute
javascript
const GD_TOKEN = 'fd7a0e4975078b5d697d478286ce46a8'
const origin = '116.310003,39.991957'
const destination = '116.434446,39.90816'
const url = `https://restapi.amap.com/v5/direction/driving?key=${GD_TOKEN}&origin=${origin}&destination=${destination}&show_fields=polyline`
const drivingData = []
const response = await fetch(url)
const data = await response.json()
data.route.paths[0].steps.forEach((step) => {
const result = step.polyline.split(';').map((item) => {
const [lng, lat] = item.split(',')
return {
longitude: Number(lng),
latitude: Number(lat),
height: 0
}
})
drivingData.push(...result)
})