| New file |
| | |
| | | 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 |
| | | } |
| | | }) |
| | | } |
| | | |
| | | // ==================== 百度地图接口 ==================== |
| | | |
| | | // 百度地图地理编码API(地址转坐标) |
| | | export function baiduGeocoding(address, city) { |
| | | // 参数验证 |
| | | if (!address) { |
| | | return Promise.reject(new Error('参数不完整,缺少地址信息')) |
| | | } |
| | | |
| | | return request({ |
| | | url: '/system/gps/baidu/geocoding', |
| | | method: 'get', |
| | | params: { |
| | | address: address, |
| | | city: city |
| | | } |
| | | }) |
| | | } |
| | | |
| | | // 百度地图路线规划API(计算两个坐标之间的驾车距离) |
| | | export function baiduRouteDriving(origin, destination) { |
| | | // 参数验证 |
| | | if (!origin || !destination) { |
| | | return Promise.reject(new Error('参数不完整,缺少起点或终点坐标')) |
| | | } |
| | | |
| | | // 验证坐标格式(纬度,经度) |
| | | const originParts = origin.split(',') |
| | | const destParts = destination.split(',') |
| | | if (originParts.length !== 2 || destParts.length !== 2) { |
| | | return Promise.reject(new Error('坐标格式错误,应为:纬度,经度')) |
| | | } |
| | | |
| | | return request({ |
| | | url: '/system/gps/baidu/route/driving', |
| | | method: 'get', |
| | | params: { |
| | | origin: origin, |
| | | destination: destination |
| | | } |
| | | }) |
| | | } |
| | | |
| | | // 百度地图计算两个地址之间的距离(组合接口:地址转坐标 + 路线规划) |
| | | export function baiduDistanceByAddress(fromAddress, fromCity, toAddress, toCity) { |
| | | // 参数验证 |
| | | if (!fromAddress || !toAddress) { |
| | | return Promise.reject(new Error('参数不完整,缺少起点或终点地址')) |
| | | } |
| | | |
| | | return request({ |
| | | url: '/system/gps/baidu/distance/byAddress', |
| | | method: 'get', |
| | | params: { |
| | | fromAddress: fromAddress, |
| | | fromCity: fromCity, |
| | | toAddress: toAddress, |
| | | toCity: toCity |
| | | } |
| | | }) |
| | | } |