wlzboy
2025-11-22 fd047fa7234dc11643dab8ecbf38e8d7a8ba0854
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
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
    }
  })
}
 
// 百度地图地址搜索提示API(输入联想)
export function baiduPlaceSuggestion(query, region) {
  // 参数验证
  if (!query) {
    return Promise.reject(new Error('参数不完整,缺少搜索关键词'))
  }
  
  return request({
    url: '/system/gps/baidu/place/suggestion',
    method: 'get',
    params: {
      query: query,
      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
    }
  })
}