expo-gaode-map-web-api 1.0.1-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,632 @@
1
+ # expo-gaode-map-web-api
2
+
3
+ 高德地图 Web API 服务模块 - 纯 JavaScript 实现,无需原生依赖
4
+
5
+ ## 特性
6
+
7
+ - ✅ **纯 JavaScript 实现**:无需原生编译,跨平台完全一致
8
+ - ✅ **TypeScript 支持**:完整的类型定义
9
+ - ✅ **文档完善**:高德 Web API 文档持续更新
10
+ - ✅ **易于调试**:可以用浏览器或 Postman 直接测试
11
+ - ✅ **零依赖**:只使用标准的 fetch API
12
+
13
+ ## 已实现功能
14
+
15
+ ### 地理编码服务
16
+ - ✅ 地理编码(地址 → 坐标)
17
+ - ✅ 逆地理编码(坐标 → 地址)
18
+ - ✅ 批量地理编码
19
+ - ✅ 批量逆地理编码
20
+
21
+ ### 路径规划服务
22
+ - ✅ 驾车路径规划
23
+ - ✅ 步行路径规划
24
+ - ✅ 骑行路径规划
25
+ - ✅ 电动车路径规划
26
+ - ✅ 公交路径规划
27
+
28
+ ## 待实现功能
29
+
30
+ - ⏳ POI 搜索
31
+ - ⏳ 天气查询
32
+ - ⏳ 行政区域查询
33
+
34
+ ## 安装
35
+
36
+ ```bash
37
+ npm install expo-gaode-map-web-api
38
+ # 或
39
+ yarn add expo-gaode-map-web-api
40
+ # 或
41
+ pnpm add expo-gaode-map-web-api
42
+ ```
43
+
44
+ ## 快速开始
45
+
46
+ ### 1. 申请 Web API Key
47
+
48
+ 1. 登录 [高德开放平台控制台](https://console.amap.com/)
49
+ 2. 创建应用
50
+ 3. 添加 **Web 服务** Key(注意:不是 iOS/Android Key)
51
+
52
+ ### 2. 基础使用
53
+
54
+ ```typescript
55
+ import { GaodeWebAPI } from 'expo-gaode-map-web-api';
56
+
57
+ // 创建实例
58
+ const api = new GaodeWebAPI({
59
+ key: 'your-web-api-key',
60
+ });
61
+
62
+ // 逆地理编码:坐标 → 地址
63
+ const result = await api.geocode.regeocode('116.481028,39.989643');
64
+ console.log(result.regeocode.formatted_address);
65
+ // 输出:北京市朝阳区阜通东大街6号
66
+
67
+ // 地理编码:地址 → 坐标
68
+ const result2 = await api.geocode.geocode('北京市朝阳区阜通东大街6号');
69
+ console.log(result2.geocodes[0].location);
70
+ // 输出:116.481028,39.989643
71
+
72
+ // 驾车路径规划
73
+ const route = await api.route.driving(
74
+ '116.481028,39.989643',
75
+ '116.434446,39.90816'
76
+ );
77
+ console.log(`距离:${route.route.paths[0].distance}米`);
78
+ console.log(`时间:${route.route.paths[0].duration}秒`);
79
+ ```
80
+
81
+ ## 详细用法
82
+
83
+ ### 逆地理编码
84
+
85
+ #### 基础用法
86
+
87
+ ```typescript
88
+ // 方式1:使用字符串(经度,纬度)
89
+ const result = await api.geocode.regeocode('116.481028,39.989643');
90
+
91
+ // 方式2:使用对象
92
+ const result = await api.geocode.regeocode({
93
+ longitude: 116.481028,
94
+ latitude: 39.989643,
95
+ });
96
+
97
+ // 获取结果
98
+ console.log(result.regeocode.formatted_address);
99
+ // 北京市朝阳区阜通东大街6号
100
+
101
+ console.log(result.regeocode.addressComponent);
102
+ // {
103
+ // country: "中国",
104
+ // province: "北京市",
105
+ // city: [],
106
+ // district: "朝阳区",
107
+ // township: "望京街道",
108
+ // street: "阜通东大街",
109
+ // number: "6号",
110
+ // ...
111
+ // }
112
+ ```
113
+
114
+ #### 高级用法
115
+
116
+ ```typescript
117
+ // 获取详细信息(附近POI、道路等)
118
+ const result = await api.geocode.regeocode('116.481028,39.989643', {
119
+ extensions: 'all', // 返回详细信息
120
+ radius: 1000, // 搜索半径1000米
121
+ poitype: '商务住宅|餐饮服务', // POI类型
122
+ });
123
+
124
+ // 获取附近POI
125
+ result.regeocode.pois?.forEach(poi => {
126
+ console.log(`${poi.name} - ${poi.distance}米`);
127
+ });
128
+
129
+ // 获取附近道路
130
+ result.regeocode.roads?.forEach(road => {
131
+ console.log(`${road.name} - ${road.distance}米`);
132
+ });
133
+ ```
134
+
135
+ #### 批量逆地理编码
136
+
137
+ ```typescript
138
+ const result = await api.geocode.batchRegeocode([
139
+ '116.481028,39.989643',
140
+ '116.434446,39.90816',
141
+ '116.397477,39.908692',
142
+ ]);
143
+
144
+ // 处理多个结果
145
+ // 注意:批量查询的结果格式与单个查询略有不同
146
+ ```
147
+
148
+ ### 地理编码
149
+
150
+ #### 基础用法
151
+
152
+ ```typescript
153
+ // 地址转坐标
154
+ const result = await api.geocode.geocode('北京市朝阳区阜通东大街6号');
155
+
156
+ console.log(result.geocodes[0].location);
157
+ // 116.481028,39.989643
158
+
159
+ console.log(result.geocodes[0].formatted_address);
160
+ // 北京市朝阳区阜通东大街6号
161
+ ```
162
+
163
+ #### 指定城市
164
+
165
+ ```typescript
166
+ // 当地址不完整时,建议指定城市
167
+ const result = await api.geocode.geocode('阜通东大街6号', '北京');
168
+
169
+ // 可以避免歧义,提高准确性
170
+ ```
171
+
172
+ #### 批量地理编码
173
+
174
+ ```typescript
175
+ const result = await api.geocode.batchGeocode(
176
+ [
177
+ '北京市朝阳区阜通东大街6号',
178
+ '北京市朝阳区望京SOHO',
179
+ '北京市海淀区中关村大街1号',
180
+ ],
181
+ '北京'
182
+ );
183
+
184
+ result.geocodes.forEach(geocode => {
185
+ console.log(`${geocode.formatted_address} → ${geocode.location}`);
186
+ });
187
+ ```
188
+
189
+ ## 在 React Native 中使用
190
+
191
+ ### 示例:显示当前位置地址
192
+
193
+ ```typescript
194
+ import React, { useState, useEffect } from 'react';
195
+ import { View, Text } from 'react-native';
196
+ import * as Location from 'expo-location';
197
+ import { GaodeWebAPI } from 'expo-gaode-map-web-api';
198
+
199
+ const api = new GaodeWebAPI({ key: 'your-key' });
200
+
201
+ export default function CurrentLocation() {
202
+ const [address, setAddress] = useState('');
203
+
204
+ useEffect(() => {
205
+ (async () => {
206
+ // 获取当前位置
207
+ const { status } = await Location.requestForegroundPermissionsAsync();
208
+ if (status !== 'granted') return;
209
+
210
+ const location = await Location.getCurrentPositionAsync();
211
+ const { longitude, latitude } = location.coords;
212
+
213
+ // 逆地理编码
214
+ const result = await api.geocode.regeocode({
215
+ longitude,
216
+ latitude,
217
+ });
218
+
219
+ setAddress(result.regeocode.formatted_address);
220
+ })();
221
+ }, []);
222
+
223
+ return (
224
+ <View>
225
+ <Text>当前位置:{address}</Text>
226
+ </View>
227
+ );
228
+ }
229
+ ```
230
+
231
+ ### 示例:搜索地址并在地图上显示
232
+
233
+ ```typescript
234
+ import React, { useState } from 'react';
235
+ import { View, TextInput, Button } from 'react-native';
236
+ import { MapView, Marker } from 'expo-gaode-map';
237
+ import { GaodeWebAPI } from 'expo-gaode-map-web-api';
238
+
239
+ const api = new GaodeWebAPI({ key: 'your-key' });
240
+
241
+ export default function SearchMap() {
242
+ const [address, setAddress] = useState('');
243
+ const [marker, setMarker] = useState(null);
244
+
245
+ const handleSearch = async () => {
246
+ // 地址转坐标
247
+ const result = await api.geocode.geocode(address, '北京');
248
+
249
+ if (result.geocodes.length > 0) {
250
+ const [lng, lat] = result.geocodes[0].location.split(',');
251
+ setMarker({
252
+ latitude: parseFloat(lat),
253
+ longitude: parseFloat(lng),
254
+ title: result.geocodes[0].formatted_address,
255
+ });
256
+ }
257
+ };
258
+
259
+ return (
260
+ <View style={{ flex: 1 }}>
261
+ <TextInput
262
+ value={address}
263
+ onChangeText={setAddress}
264
+ placeholder="输入地址"
265
+ />
266
+ <Button title="搜索" onPress={handleSearch} />
267
+
268
+ <MapView style={{ flex: 1 }}>
269
+ {marker && <Marker {...marker} />}
270
+ </MapView>
271
+ </View>
272
+ );
273
+ }
274
+ ```
275
+
276
+ ### 路径规划(新版 V5 API)
277
+
278
+ #### 驾车路径规划
279
+
280
+ ```typescript
281
+ import { DrivingStrategy } from 'expo-gaode-map-web-api';
282
+
283
+ // 基础用法
284
+ const result = await api.route.driving(
285
+ '116.481028,39.989643',
286
+ '116.434446,39.90816'
287
+ );
288
+
289
+ console.log(`距离:${result.route.paths[0].distance}米`);
290
+ console.log(`时间:${result.route.paths[0].duration}秒`);
291
+ console.log(`收费:${result.route.paths[0].tolls}元`);
292
+
293
+ // 高级用法:带途经点和策略(新版 V5 API)
294
+ const result = await api.route.driving(
295
+ { longitude: 116.481028, latitude: 39.989643 },
296
+ { longitude: 116.434446, latitude: 39.90816 },
297
+ {
298
+ waypoints: ['116.45,39.95', '116.46,39.94'], // 途经点
299
+ strategy: DrivingStrategy.AVOID_JAM, // 躲避拥堵(新版使用33)
300
+ show_fields: 'cost,navi,polyline', // 返回成本、导航、坐标信息
301
+ plate: '京AHA322', // 车牌号(用于判断限行)
302
+ cartype: 0, // 车辆类型:0-燃油,1-纯电,2-插混
303
+ ferry: 0, // 是否使用轮渡:0-使用,1-不使用
304
+ }
305
+ );
306
+
307
+ // 新能源车路径规划
308
+ const result = await api.route.driving(
309
+ '116.481028,39.989643',
310
+ '116.434446,39.90816',
311
+ {
312
+ cartype: 1, // 纯电动汽车
313
+ plate: '京AD12345', // 新能源车牌
314
+ strategy: DrivingStrategy.DEFAULT, // 高德推荐策略
315
+ }
316
+ );
317
+ ```
318
+
319
+ #### 步行路径规划
320
+
321
+ ```typescript
322
+ // 基础用法
323
+ const result = await api.route.walking(
324
+ '116.481028,39.989643',
325
+ '116.434446,39.90816'
326
+ );
327
+
328
+ console.log(`步行距离:${result.route.paths[0].distance}米`);
329
+ console.log(`预计时间:${result.route.paths[0].duration}秒`);
330
+ console.log(`打车费用:${result.route.paths[0].taxi}元`);
331
+
332
+ // 高级用法:多路线 + 详细信息
333
+ const result = await api.route.walking(
334
+ '116.481028,39.989643',
335
+ '116.434446,39.90816',
336
+ {
337
+ alternative_route: 3, // 返回3条路线
338
+ show_fields: 'cost,navi,polyline', // 返回成本、导航、坐标
339
+ origin_id: 'B000A83M2Z', // 起点POI ID(提升准确性)
340
+ destination_id: 'B000A83M30', // 终点POI ID
341
+ isindoor: 1, // 需要室内算路
342
+ }
343
+ );
344
+
345
+ // 获取每一步的导航信息
346
+ result.route.paths[0].steps.forEach((step, index) => {
347
+ console.log(`第${index + 1}步:${step.instruction}`);
348
+ console.log(` 道路:${step.road_name || '无名路'}`);
349
+ console.log(` 距离:${step.step_distance}米`);
350
+ console.log(` 道路类型:${step.walk_type}`); // 0-普通道路,1-人行横道等
351
+ });
352
+ ```
353
+
354
+ #### 骑行路径规划
355
+
356
+ ```typescript
357
+ // 基础用法
358
+ const result = await api.route.bicycling(
359
+ '116.481028,39.989643',
360
+ '116.434446,39.90816'
361
+ );
362
+
363
+ // 高级用法:多路线
364
+ const result = await api.route.bicycling(
365
+ '116.481028,39.989643',
366
+ '116.434446,39.90816',
367
+ {
368
+ alternative_route: 2, // 返回2条路线
369
+ show_fields: 'cost,navi,polyline' // 返回详细信息
370
+ }
371
+ );
372
+ ```
373
+
374
+ #### 电动车路径规划
375
+
376
+ ```typescript
377
+ const result = await api.route.electricBike(
378
+ '116.481028,39.989643',
379
+ '116.434446,39.90816',
380
+ {
381
+ alternative_route: 3, // 返回3条路线
382
+ show_fields: 'cost,navi,polyline'
383
+ }
384
+ );
385
+ ```
386
+
387
+ #### 公交路径规划
388
+
389
+ ```typescript
390
+ import { TransitStrategy } from 'expo-gaode-map-web-api';
391
+
392
+ // 同城公交(新版 V5 API:city1 和 city2 必填,使用 citycode)
393
+ const result = await api.route.transit(
394
+ '116.481028,39.989643',
395
+ '116.434446,39.90816',
396
+ '010', // 起点城市 citycode(北京)
397
+ '010', // 终点城市 citycode(北京)
398
+ {
399
+ strategy: TransitStrategy.RECOMMENDED, // 推荐模式(默认)
400
+ show_fields: 'cost,polyline', // 返回成本和坐标信息
401
+ AlternativeRoute: 3, // 返回3条路线
402
+ }
403
+ );
404
+
405
+ // 跨城公交
406
+ const result = await api.route.transit(
407
+ '116.481028,39.989643',
408
+ '121.472644,31.231706',
409
+ '010', // 北京 citycode
410
+ '021', // 上海 citycode
411
+ {
412
+ strategy: TransitStrategy.TIME_FIRST, // 时间最短
413
+ nightflag: 1, // 考虑夜班车
414
+ date: '2024-12-08', // 请求日期
415
+ time: '9:00', // 出发时间
416
+ }
417
+ );
418
+
419
+ // 地铁图模式(起终点都是地铁站)
420
+ const result = await api.route.transit(
421
+ '116.481028,39.989643',
422
+ '116.434446,39.90816',
423
+ '010',
424
+ '010',
425
+ {
426
+ strategy: TransitStrategy.SUBWAY_MAP, // 地铁图模式
427
+ originpoi: 'B000A83M2Z', // 起点地铁站POI ID(必填)
428
+ destinationpoi: 'B000A83M30', // 终点地铁站POI ID(必填)
429
+ multiexport: 1, // 返回全部地铁出入口
430
+ }
431
+ );
432
+
433
+ // 处理公交换乘方案
434
+ result.route.transits.forEach((transit, index) => {
435
+ console.log(`\n方案${index + 1}:`);
436
+ console.log(`总费用:${transit.cost}元`);
437
+ console.log(`总时间:${transit.duration}秒`);
438
+ console.log(`步行距离:${transit.walking_distance}米`);
439
+ console.log(`是否夜班车:${transit.nightflag === '1' ? '是' : '否'}`);
440
+
441
+ transit.segments.forEach((segment, segIndex) => {
442
+ if (segment.walking) {
443
+ console.log(` ${segIndex + 1}. 步行 ${segment.walking.distance}米`);
444
+ } else if (segment.bus) {
445
+ const line = segment.bus.buslines[0];
446
+ console.log(` ${segIndex + 1}. 乘坐 ${line.name}`);
447
+ console.log(` ${line.departure_stop.name} → ${line.arrival_stop.name}`);
448
+ console.log(` 途经${line.via_num}站,${line.distance}米`);
449
+ }
450
+ });
451
+ });
452
+ ```
453
+
454
+ ## API 参考
455
+
456
+ ### GaodeWebAPI
457
+
458
+ 主类,用于创建 API 实例。
459
+
460
+ #### 构造函数
461
+
462
+ ```typescript
463
+ new GaodeWebAPI(config: ClientConfig)
464
+ ```
465
+
466
+ #### 配置选项
467
+
468
+ ```typescript
469
+ interface ClientConfig {
470
+ /** Web API Key */
471
+ key: string;
472
+ /** 基础URL,默认:https://restapi.amap.com */
473
+ baseURL?: string;
474
+ /** 请求超时(毫秒),默认:10000 */
475
+ timeout?: number;
476
+ }
477
+ ```
478
+
479
+ #### 服务
480
+
481
+ **geocode - 地理编码服务**
482
+ - `regeocode()` - 逆地理编码
483
+ - `geocode()` - 地理编码
484
+ - `batchRegeocode()` - 批量逆地理编码
485
+ - `batchGeocode()` - 批量地理编码
486
+
487
+ **route - 路径规划服务**
488
+ - `driving()` - 驾车路径规划
489
+ - `walking()` - 步行路径规划
490
+ - `bicycling()` - 骑行路径规划
491
+ - `electricBike()` - 电动车路径规划
492
+ - `transit()` - 公交路径规划
493
+
494
+ **工具方法**
495
+ - `setKey(key)` - 更新 API Key
496
+ - `getKey()` - 获取当前 API Key
497
+
498
+ ### 逆地理编码参数详解
499
+
500
+ #### regeocode(location, options?)
501
+
502
+ | 参数 | 类型 | 必填 | 说明 |
503
+ |------|------|------|------|
504
+ | location | string \| Coordinate | 是 | 经纬度坐标,格式:"经度,纬度" 或 {longitude, latitude} |
505
+ | options.poitype | string | 否 | 返回附近POI类型,多个类型用"\|"分隔,如:"商务住宅\|餐饮服务" |
506
+ | options.radius | number | 否 | 搜索半径,取值范围:0-3000,默认1000米 |
507
+ | options.extensions | 'base' \| 'all' | 否 | 返回结果控制:base(基本信息,默认)/all(详细信息,包含POI、道路等) |
508
+ | options.roadlevel | 0 \| 1 | 否 | 道路等级:0(全部道路)/1(高速+国道+省道+县道+乡镇村道) |
509
+ | options.homeorcorp | 0 \| 1 \| 2 | 否 | 是否优化POI返回顺序:0(不优化)/1(优化为家)/2(优化为公司) |
510
+ | options.sig | string | 否 | 数字签名,签名校验型key需要传递此参数 |
511
+ | options.output | 'JSON' \| 'XML' | 否 | 返回数据格式,默认JSON |
512
+ | options.callback | string | 否 | 回调函数名,仅output为JSON时有效 |
513
+
514
+ #### 返回值字段说明
515
+
516
+ **AddressComponent(地址组成元素)**
517
+
518
+ | 字段 | 说明 | 示例 |
519
+ |------|------|------|
520
+ | country | 国家名称 | "中国" |
521
+ | province | 省份名称 | "北京市" |
522
+ | city | 城市名称(直辖市/省直辖县可能为空) | "北京市" 或 [] |
523
+ | citycode | 城市编码 | "010" |
524
+ | district | 区县名称 | "海淀区" |
525
+ | adcode | 行政区编码 | "110108" |
526
+ | township | 乡镇/街道(社区街道,非道路) | "燕园街道" |
527
+ | towncode | 乡镇街道编码 | "110101001000" |
528
+ | street | 街道名称 | "中关村北二条" |
529
+ | number | 门牌号 | "3号" |
530
+ | seaArea | 所属海域信息(可选) | "渤海" |
531
+
532
+ ### 地理编码参数详解
533
+
534
+ #### geocode(address, city?, options?)
535
+
536
+ | 参数 | 类型 | 必填 | 说明 |
537
+ |------|------|------|------|
538
+ | address | string | 是 | 结构化地址信息,地址信息越完整,解析精度越高 |
539
+ | city | string | 否 | 指定查询的城市,支持:城市中文、全拼、citycode、adcode。例如:"北京市"/"beijing"/"010"/"110000" |
540
+ | options.sig | string | 否 | 数字签名,签名校验型key需要传递此参数 |
541
+ | options.output | 'JSON' \| 'XML' | 否 | 返回数据格式,默认JSON |
542
+ | options.callback | string | 否 | 回调函数名,仅output为JSON时有效 |
543
+
544
+ #### 批量查询说明
545
+
546
+ - **批量逆地理编码**:最多支持 20 个坐标点,坐标用"|"分隔
547
+ - **批量地理编码**:最多支持 10 个地址,地址用"|"分隔
548
+
549
+ ### 路径规划参数详解
550
+
551
+ #### driving(origin, destination, options?)
552
+
553
+ **驾车路径规划策略(新版 V5 API)**
554
+
555
+ | 策略值 | 说明 |
556
+ |--------|------|
557
+ | `DrivingStrategy.SPEED_FIRST` (0) | 速度优先(旧版,只返回一条路线) |
558
+ | `DrivingStrategy.COST_FIRST` (1) | 费用优先(旧版,不走收费路段) |
559
+ | `DrivingStrategy.REGULAR_FASTEST` (2) | 常规最快(旧版) |
560
+ | `DrivingStrategy.DEFAULT` (32) | **默认,高德推荐(推荐使用)** |
561
+ | `DrivingStrategy.AVOID_JAM` (33) | 躲避拥堵 |
562
+ | `DrivingStrategy.HIGHWAY_FIRST` (34) | 高速优先 |
563
+ | `DrivingStrategy.NO_HIGHWAY` (35) | 不走高速 |
564
+ | `DrivingStrategy.LESS_TOLL` (36) | 少收费 |
565
+ | `DrivingStrategy.MAIN_ROAD_FIRST` (37) | 大路优先 |
566
+ | `DrivingStrategy.FASTEST` (38) | 速度最快 |
567
+ | `DrivingStrategy.AVOID_JAM_HIGHWAY_FIRST` (39) | 躲避拥堵 + 高速优先 |
568
+ | `DrivingStrategy.AVOID_JAM_NO_HIGHWAY` (40) | 躲避拥堵 + 不走高速 |
569
+ | `DrivingStrategy.AVOID_JAM_LESS_TOLL` (41) | 躲避拥堵 + 少收费 |
570
+ | `DrivingStrategy.LESS_TOLL_NO_HIGHWAY` (42) | 少收费 + 不走高速 |
571
+ | `DrivingStrategy.AVOID_JAM_LESS_TOLL_NO_HIGHWAY` (43) | 躲避拥堵 + 少收费 + 不走高速 |
572
+ | `DrivingStrategy.AVOID_JAM_MAIN_ROAD` (44) | 躲避拥堵 + 大路优先 |
573
+ | `DrivingStrategy.AVOID_JAM_FASTEST` (45) | 躲避拥堵 + 速度最快 |
574
+
575
+ **车辆类型(新版 V5 API)**
576
+
577
+ | 值 | 说明 |
578
+ |----|------|
579
+ | 0 | 普通燃油汽车(默认) |
580
+ | 1 | 纯电动汽车 |
581
+ | 2 | 插电式混动汽车 |
582
+
583
+ #### transit(origin, destination, city1, city2, options?)
584
+
585
+ **公交换乘策略(新版 V5 API)**
586
+
587
+ | 策略值 | 说明 |
588
+ |--------|------|
589
+ | `TransitStrategy.RECOMMENDED` (0) | 推荐模式,综合权重(默认) |
590
+ | `TransitStrategy.CHEAPEST` (1) | 最经济模式,票价最低 |
591
+ | `TransitStrategy.LEAST_TRANSFER` (2) | 最少换乘模式 |
592
+ | `TransitStrategy.LEAST_WALK` (3) | 最少步行模式 |
593
+ | `TransitStrategy.MOST_COMFORTABLE` (4) | 最舒适模式,尽量乘坐空调车 |
594
+ | `TransitStrategy.NO_SUBWAY` (5) | 不乘地铁模式 |
595
+ | `TransitStrategy.SUBWAY_MAP` (6) | 地铁图模式(起终点都是地铁站,需提供POI ID) |
596
+ | `TransitStrategy.SUBWAY_FIRST` (7) | 地铁优先模式(步行距离不超过4KM) |
597
+ | `TransitStrategy.TIME_FIRST` (8) | 时间短模式,总时间最少 |
598
+
599
+ ## 错误处理
600
+
601
+ ```typescript
602
+ try {
603
+ const result = await api.geocode.regeocode('116.481028,39.989643');
604
+ console.log(result.regeocode.formatted_address);
605
+ } catch (error) {
606
+ if (error instanceof Error) {
607
+ console.error('错误:', error.message);
608
+ // 可能的错误:
609
+ // - "API Error: INVALID_USER_KEY (code: 10001)" - Key无效
610
+ // - "API Error: DAILY_QUERY_OVER_LIMIT (code: 10003)" - 超过每日限额
611
+ // - "Request timeout after 10000ms" - 请求超时
612
+ }
613
+ }
614
+ ```
615
+
616
+ ## 注意事项
617
+
618
+ 1. **Key 类型**:必须使用 Web 服务 Key,不能使用 iOS/Android Key
619
+ 2. **配额限制**:个人开发者每天30万次免费额度
620
+ 3. **坐标格式**:经度在前,纬度在后(经度,纬度)
621
+ 4. **网络请求**:需要网络连接,无法离线使用
622
+ 5. **跨域问题**:Web 端可能遇到跨域,建议使用代理或服务端请求
623
+
624
+ ## 相关资源
625
+
626
+ - [高德地图 Web API 文档](https://lbs.amap.com/api/webservice/summary)
627
+ - [expo-gaode-map 核心模块](../core)
628
+ - [expo-gaode-map-navigation 导航模块](../navigation)
629
+
630
+ ## License
631
+
632
+ MIT