Commit 14bee6f5 by 李伟康

新增路线规划 & 输入提示

1 parent af0b376b
......@@ -20,7 +20,7 @@ class GlMapApi {
* @param {*} type 0:直线距离 , 1:驾车导航距离(仅支持国内坐标) , 3:步行规划距离(仅支持5km之间的距离)
* @returns {Promise<{elements: Array}>}
*/
async calculateDistance(from, to, type = 1) {
async calculateDistance (from, to, type = 1) {
try {
const destination = JSON.parse(JSON.stringify(from)).reverse().join(','),
origins = JSON.parse(JSON.stringify(to)).reverse().join(','),
......@@ -39,11 +39,11 @@ class GlMapApi {
/**
* 批量距离计算(矩阵)
* @param {*} from 起始位置 [lat,lng]
* @param {*} toList 重点位置 [[lat,lng],[lat,lng]]
* @param {*} toList 终点位置 [[lat,lng],[lat,lng]]
* @param {*} type 直线距离 , 1:驾车导航距离(仅支持国内坐标) , 3:步行规划距离(仅支持5km之间的距离)
* @returns {Promise<{rows: Array}>}
*/
async calculateDistanceMatrix(from, toList, type = 1) {
async calculateDistanceMatrix (from, toList, type = 1) {
try {
const destination = JSON.parse(JSON.stringify(from)).reverse().join(','),
origins = JSON.parse(JSON.stringify(toList))
......@@ -72,7 +72,7 @@ class GlMapApi {
* @param {*} address (String)
* @returns
*/
geocoder(address) {
geocoder (address) {
return this.request.get('/v3/geocode/geo', {
address
})
......@@ -82,12 +82,12 @@ class GlMapApi {
* @param {*} location [lat<纬度>,lng<经度>]
* @returns
*/
async detailedAdrress(location) {
async detailedAdrress (location) {
try {
const [lat, lng] = location
const { regeocode } = await this.request.get('/v3/geocode/regeo', {
location: JSON.parse(JSON.stringify(location)).reverse().join(',')
}),
location: JSON.parse(JSON.stringify(location)).reverse().join(',')
}),
{ addressComponent, formatted_address } = regeocode,
address = `${addressComponent.province || ''}${addressComponent.city || ''}${addressComponent.district || ''}${addressComponent.township || ''}`,
data = {
......@@ -134,7 +134,7 @@ class GlMapApi {
* IP定位
* @returns
*/
getLocationByIp() {
getLocationByIp () {
return this.request.get('/v3/ip')
}
/**
......@@ -147,7 +147,7 @@ class GlMapApi {
autonavi(不进行转换))
* @returns
*/
translate(locationsList, coordsys = 'autonavi') {
translate (locationsList, coordsys = 'autonavi') {
// 使用数组解构和map方法,将locationsList参数转换为字符串,并反转数组顺序,然后用竖线连接,得到locations字符串
const locations = JSON.parse(JSON.stringify(locationsList))
.map(e => (e = e.reverse()))
......@@ -158,5 +158,47 @@ class GlMapApi {
coordsys
})
}
/**
* 路线规划
* @param {*} from 起始位置 [lat,lng] 纬度前,经度后
* @param {*} to 终点位置 [lat,lng] 纬度前,经度后
* @param {*} type 出行类型 1步行 2骑车 3驾车
*/
async routePlanning (from, to, type = 3) {
const funName = {
1: '/v3/direction/walking',
2: '/v4/direction/bicycling',
3: '/v3/direction/driving'
}[type],
origin = JSON.parse(JSON.stringify(from)).reverse().join(','),
destination = JSON.parse(JSON.stringify(to)).reverse().join(',')
try {
const { route } = await this.request.get(funName, {
origin,
destination
})
return Promise.resolve(route)
} catch (error) {
return Promise.reject(error)
}
}
/**
* 输入提示
* @param {*} keywords 查询关键词
* @param {*} location 定位坐标 [lat,lng] 纬度前,经度后
*/
async keywordSearch (keywords, location) {
try {
const { route } = await this.request.get('/v3/assistant/inputtips', {
keywords,
location: JSON.parse(JSON.stringify(location)).reverse().join(',')
})
return Promise.resolve(route)
} catch (error) {
return Promise.reject(error)
}
}
}
export default GlMapApi
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!