import request from '@/utils/request'
|
|
// 地图地址搜索API
|
export function searchAddress(keyword, region) {
|
// 参数验证
|
if (!keyword) {
|
return Promise.reject(new Error('参数不完整,缺少关键词'))
|
}
|
|
return request({
|
url: '/system/gps/address/search',
|
method: 'get',
|
params: {
|
keyword: keyword,
|
region: region || '广州'
|
}
|
})
|
}
|
|
// 地图逆地址解析API
|
export function reverseGeocoder(lat, lng) {
|
// 参数验证
|
if (lat === undefined || lat === null || lng === undefined || lng === null) {
|
return Promise.reject(new Error('参数不完整,缺少经纬度坐标'))
|
}
|
|
// 检查参数有效性
|
if (isNaN(lat) || isNaN(lng)) {
|
return Promise.reject(new Error('参数无效,经纬度坐标格式错误'))
|
}
|
|
return request({
|
url: '/system/gps/address/geocoder',
|
method: 'get',
|
params: {
|
lat: lat,
|
lng: lng
|
}
|
})
|
}
|
|
// 地图路线规划API(计算两点间距离)
|
export function calculateDistance(fromLat, fromLng, toLat, toLng) {
|
// 参数验证
|
if (fromLat === undefined || fromLat === null ||
|
fromLng === undefined || fromLng === null ||
|
toLat === undefined || toLat === null ||
|
toLng === undefined || toLng === null) {
|
return Promise.reject(new Error('参数不完整,缺少起点或终点坐标'))
|
}
|
|
// 检查参数有效性
|
if (isNaN(fromLat) || isNaN(fromLng) || isNaN(toLat) || isNaN(toLng)) {
|
return Promise.reject(new Error('参数无效,坐标格式错误'))
|
}
|
|
return request({
|
url: '/system/gps/route/distance',
|
method: 'get',
|
params: {
|
fromLat: fromLat,
|
fromLng: fromLng,
|
toLat: toLat,
|
toLng: toLng
|
}
|
})
|
}
|