wlzboy
1 天以前 08f95b2f159b56fa3bd4f4b348855989de8aa456
app/api/map.js
@@ -8,7 +8,8 @@
  }
  
  return request({
    url: '/system/gps/address/search',
//    url: '/system/gps/address/search',
    url: '/system/gps/tianditu/place/suggestion',
    method: 'get',
    params: {
      keyword: keyword,
@@ -28,9 +29,12 @@
  if (isNaN(lat) || isNaN(lng)) {
    return Promise.reject(new Error('参数无效,经纬度坐标格式错误'))
  }
  /**
   * 这里用到天地图
   */
  return request({
    url: '/system/gps/address/geocoder',
    // url: '/system/gps/address/geocoder',
    url: '/system/gps/tianditu/reverseGeocoding',
    method: 'get',
    params: {
      lat: lat,
@@ -39,6 +43,21 @@
  })
}
export function calculateTianDiTuDistance(fromAddress, toAddress) {
  // 参数验证
  if (!fromAddress || !toAddress) {
    return Promise.reject(new Error('参数不完整,缺少地址'))
  }
  return request({
    url: '/system/gps/tianditu/distance/byAddress',
    method: 'get',
    params: {
      fromAddress: fromAddress,
      toAddress: toAddress
    }
  })
}
// 地图路线规划API(计算两点间距离)
export function calculateDistance(fromLat, fromLng, toLat, toLng) {
  // 参数验证
@@ -56,6 +75,7 @@
  
  return request({
    url: '/system/gps/route/distance',
    // url: '/system/gps/tianditu/byAddress',
    method: 'get',
    params: {
      fromLat: fromLat,
@@ -84,6 +104,9 @@
    }
  })
}
// 别名,与baiduGeocoding功能相同
export const baiduGeocode = baiduGeocoding
// 百度地图路线规划API(计算两个坐标之间的驾车距离)
export function baiduRouteDriving(origin, destination) {
@@ -143,4 +166,127 @@
      region: region || '广州'
    }
  })
}
}
// ==================== 天地图接口 ====================
// 天地图地理编码API(地址转坐标)
export function tiandituGeocoding(address) {
  // 参数验证
  if (!address) {
    return Promise.reject(new Error('参数不完整,缺少地址信息'))
  }
  return request({
    url: '/system/gps/tianditu/geocoding',
    method: 'get',
    params: {
      address: address
    }
  })
}
// 天地图逆地理编码API(坐标转地址)
export function tiandituReverseGeocoding(lon, lat) {
  // 参数验证
  if (lat === undefined || lat === null || lon === undefined || lon === null) {
    return Promise.reject(new Error('参数不完整,缺少经纬度坐标'))
  }
  // 检查参数有效性
  if (isNaN(lat) || isNaN(lon)) {
    return Promise.reject(new Error('参数无效,经纬度坐标格式错误'))
  }
  return request({
    url: '/system/gps/tianditu/reverseGeocoding',
    method: 'get',
    params: {
      lon: lon,
      lat: lat
    }
  })
}
// 天地图POI搜索API
export function tiandituPlaceSearch(keyWord, queryType, level, mapBound, start, count) {
  // 参数验证
  if (!keyWord) {
    return Promise.reject(new Error('参数不完整,缺少搜索关键词'))
  }
  return request({
    url: '/system/gps/tianditu/place/search',
    method: 'get',
    params: {
      keyWord: keyWord,
      queryType: queryType || '1',
      level: level,
      mapBound: mapBound,
      start: start || 0,
      count: count || 10
    }
  })
}
// 天地图驾车路径规划API
export function tiandituRouteDriving(orig, dest, mid, style) {
  // 参数验证
  if (!orig || !dest) {
    return Promise.reject(new Error('参数不完整,缺少起点或终点坐标'))
  }
  // 验证坐标格式(经度,纬度)
  const origParts = orig.split(',')
  const destParts = dest.split(',')
  if (origParts.length !== 2 || destParts.length !== 2) {
    return Promise.reject(new Error('坐标格式错误,应为:经度,纬度'))
  }
  return request({
    url: '/system/gps/tianditu/route/driving',
    method: 'get',
    params: {
      orig: orig,
      dest: dest,
      mid: mid,
      style: style || '0'
    }
  })
}
// 天地图计算两个地址之间的距离(组合接口:地址转坐标 + 路径规划)
export function tiandituDistanceByAddress(fromAddress, toAddress) {
  // 参数验证
  if (!fromAddress || !toAddress) {
    return Promise.reject(new Error('参数不完整,缺少起点或终点地址'))
  }
  return request({
    url: '/system/gps/tianditu/distance/byAddress',
    method: 'get',
    params: {
      fromAddress: fromAddress,
      toAddress: toAddress
    }
  })
}
// 天地图普通搜索服务API(地址搜索)
export function tiandituPlaceSuggestion(keyWord, region, city, count) {
  // 参数验证
  if (!keyWord) {
    return Promise.reject(new Error('参数不完整,缺少搜索关键词'))
  }
  return request({
    url: '/system/gps/tianditu/place/suggestion',
    method: 'get',
    params: {
      keyWord: keyWord,
      region: region,
      city: city,
      count: count || 10
    }
  })
}