expo-gaode-map-web-api 1.0.1-next.0 → 1.0.1-next.1
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 +89 -58
- package/package.json +1 -1
- package/package.json.backup +1 -1
package/README.md
CHANGED
|
@@ -1,38 +1,39 @@
|
|
|
1
1
|
# expo-gaode-map-web-api
|
|
2
2
|
|
|
3
|
-
高德地图 Web API
|
|
3
|
+
高德地图 Web API 服务模块(纯 JavaScript 实现),提供地理编码、路径规划、POI 搜索、输入提示等服务能力。支持与导航模块或核心地图模块协同,统一在应用初始化时下发 Web 服务 Key,随后直接无参构造使用。
|
|
4
4
|
|
|
5
5
|
## 特性
|
|
6
6
|
|
|
7
|
-
- ✅
|
|
8
|
-
- ✅
|
|
9
|
-
- ✅
|
|
10
|
-
- ✅
|
|
11
|
-
- ✅
|
|
7
|
+
- ✅ 纯 JavaScript:跨平台一致,无原生编译依赖(使用标准 `fetch`)
|
|
8
|
+
- ✅ TypeScript:完整类型定义与错误码映射
|
|
9
|
+
- ✅ 已适配新版 V5 路径规划策略与字段
|
|
10
|
+
- ✅ 与地图/导航模块协作:从基础初始化动态解析 Web Key,支持无参构造
|
|
11
|
+
- ✅ 运行时错误友好:封装 `GaodeAPIError`,提供错误码中文说明与排查建议
|
|
12
12
|
|
|
13
13
|
## 已实现功能
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
- ✅ 地理编码(地址 → 坐标)
|
|
17
|
-
- ✅ 逆地理编码(坐标 → 地址)
|
|
18
|
-
- ✅ 批量地理编码
|
|
19
|
-
-
|
|
15
|
+
- 地理编码服务
|
|
16
|
+
- ✅ 地理编码(地址 → 坐标)
|
|
17
|
+
- ✅ 逆地理编码(坐标 → 地址)
|
|
18
|
+
- ✅ 批量地理编码 / 批量逆地理编码
|
|
19
|
+
- 路径规划服务(V5)
|
|
20
|
+
- ✅ 驾车(支持策略、成本、导航步骤、坐标点串等)
|
|
21
|
+
- ✅ 步行(支持多路线、导航步骤、坐标点串)
|
|
22
|
+
- ✅ 骑行 / 电动车(含成本与导航步骤)
|
|
23
|
+
- ✅ 公交(含多策略、跨城、地铁图模式、出入口等)
|
|
24
|
+
- 搜索服务
|
|
25
|
+
- ✅ POI 搜索(关键字、周边、类型、详情)
|
|
26
|
+
- ✅ 输入提示(POI/公交站点/公交线路)
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
- ✅ 驾车路径规划
|
|
23
|
-
- ✅ 步行路径规划
|
|
24
|
-
- ✅ 骑行路径规划
|
|
25
|
-
- ✅ 电动车路径规划
|
|
26
|
-
- ✅ 公交路径规划
|
|
27
|
-
|
|
28
|
-
## 待实现功能
|
|
28
|
+
## 安装
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
- ⏳ 天气查询
|
|
32
|
-
- ⏳ 行政区域查询
|
|
30
|
+
本模块要求先安装且初始化基础地图组件(导航模块或核心地图模块其一即可),用于提供 Web API Key:
|
|
33
31
|
|
|
34
|
-
|
|
32
|
+
- 任选其一:
|
|
33
|
+
- `expo-gaode-map-navigation`(导航一体化,内置地图能力)
|
|
34
|
+
- `expo-gaode-map`(核心地图)
|
|
35
35
|
|
|
36
|
+
安装本模块:
|
|
36
37
|
```bash
|
|
37
38
|
npm install expo-gaode-map-web-api
|
|
38
39
|
# 或
|
|
@@ -40,42 +41,46 @@ yarn add expo-gaode-map-web-api
|
|
|
40
41
|
# 或
|
|
41
42
|
pnpm add expo-gaode-map-web-api
|
|
42
43
|
```
|
|
44
|
+
注:若未安装上述基础包,安装时或运行时会给出明确提示。
|
|
43
45
|
|
|
44
46
|
## 快速开始
|
|
45
47
|
|
|
46
|
-
### 1. 申请 Web
|
|
48
|
+
### 1. 申请 Web 服务 Key
|
|
49
|
+
- 登录 [高德开放平台控制台](https://console.amap.com/)
|
|
50
|
+
- 创建应用,添加“Web 服务”Key(注意:不是 iOS/Android Key)
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
### 2. 在基础模块初始化时下发 webKey
|
|
53
|
+
以导航模块为例(核心模块同理):
|
|
54
|
+
```ts
|
|
55
|
+
import { ExpoGaodeMapModule } from 'expo-gaode-map-navigation';
|
|
51
56
|
|
|
52
|
-
|
|
57
|
+
ExpoGaodeMapModule.initSDK({
|
|
58
|
+
androidKey: 'your-android-key',
|
|
59
|
+
iosKey: 'your-ios-key',
|
|
60
|
+
webKey: 'your-web-api-key', // 关键:供 Web API 包读取
|
|
61
|
+
});
|
|
62
|
+
```
|
|
53
63
|
|
|
54
|
-
|
|
64
|
+
### 3. 无参构造并使用
|
|
65
|
+
```ts
|
|
55
66
|
import { GaodeWebAPI } from 'expo-gaode-map-web-api';
|
|
56
67
|
|
|
57
|
-
//
|
|
58
|
-
const api = new GaodeWebAPI(
|
|
59
|
-
key: 'your-web-api-key',
|
|
60
|
-
});
|
|
68
|
+
// 无参:从基础模块运行时解析 webKey
|
|
69
|
+
const api = new GaodeWebAPI();
|
|
61
70
|
|
|
62
71
|
// 逆地理编码:坐标 → 地址
|
|
63
72
|
const result = await api.geocode.regeocode('116.481028,39.989643');
|
|
64
73
|
console.log(result.regeocode.formatted_address);
|
|
65
|
-
// 输出:北京市朝阳区阜通东大街6号
|
|
66
74
|
|
|
67
75
|
// 地理编码:地址 → 坐标
|
|
68
|
-
const
|
|
69
|
-
console.log(
|
|
70
|
-
// 输出:116.481028,39.989643
|
|
76
|
+
const geo = await api.geocode.geocode('北京市朝阳区阜通东大街6号');
|
|
77
|
+
console.log(geo.geocodes[0].location);
|
|
71
78
|
|
|
72
|
-
//
|
|
73
|
-
const route = await api.route.driving(
|
|
74
|
-
'
|
|
75
|
-
|
|
76
|
-
);
|
|
77
|
-
console.log(`距离:${route.route.paths[0].distance}米`);
|
|
78
|
-
console.log(`时间:${route.route.paths[0].duration}秒`);
|
|
79
|
+
// 驾车路径规划(V5)
|
|
80
|
+
const route = await api.route.driving('116.481028,39.989643', '116.434446,39.90816', {
|
|
81
|
+
show_fields: 'cost,navi,polyline',
|
|
82
|
+
});
|
|
83
|
+
console.log(route.route.paths[0].distance);
|
|
79
84
|
```
|
|
80
85
|
|
|
81
86
|
## 详细用法
|
|
@@ -196,7 +201,7 @@ import { View, Text } from 'react-native';
|
|
|
196
201
|
import * as Location from 'expo-location';
|
|
197
202
|
import { GaodeWebAPI } from 'expo-gaode-map-web-api';
|
|
198
203
|
|
|
199
|
-
const api = new GaodeWebAPI(
|
|
204
|
+
const api = new GaodeWebAPI();
|
|
200
205
|
|
|
201
206
|
export default function CurrentLocation() {
|
|
202
207
|
const [address, setAddress] = useState('');
|
|
@@ -233,10 +238,11 @@ export default function CurrentLocation() {
|
|
|
233
238
|
```typescript
|
|
234
239
|
import React, { useState } from 'react';
|
|
235
240
|
import { View, TextInput, Button } from 'react-native';
|
|
236
|
-
|
|
241
|
+
// 如在“导航一体化模块”渲染地图,推荐:
|
|
242
|
+
import { MapView, Marker } from 'expo-gaode-map-navigation';
|
|
237
243
|
import { GaodeWebAPI } from 'expo-gaode-map-web-api';
|
|
238
244
|
|
|
239
|
-
const api = new GaodeWebAPI(
|
|
245
|
+
const api = new GaodeWebAPI();
|
|
240
246
|
|
|
241
247
|
export default function SearchMap() {
|
|
242
248
|
const [address, setAddress] = useState('');
|
|
@@ -460,15 +466,17 @@ result.route.transits.forEach((transit, index) => {
|
|
|
460
466
|
#### 构造函数
|
|
461
467
|
|
|
462
468
|
```typescript
|
|
463
|
-
new GaodeWebAPI(config
|
|
469
|
+
new GaodeWebAPI(config?: ClientConfig)
|
|
464
470
|
```
|
|
465
471
|
|
|
472
|
+
- 若未传 `config.key`,会自动从基础模块(`expo-gaode-map` 或 `expo-gaode-map-navigation`)的初始化中解析 `webKey`,未解析到时会抛出明确错误。
|
|
473
|
+
|
|
466
474
|
#### 配置选项
|
|
467
475
|
|
|
468
476
|
```typescript
|
|
469
477
|
interface ClientConfig {
|
|
470
|
-
/** Web API Key */
|
|
471
|
-
key
|
|
478
|
+
/** Web API Key(可选;通常从基础模块解析) */
|
|
479
|
+
key?: string;
|
|
472
480
|
/** 基础URL,默认:https://restapi.amap.com */
|
|
473
481
|
baseURL?: string;
|
|
474
482
|
/** 请求超时(毫秒),默认:10000 */
|
|
@@ -495,6 +503,29 @@ interface ClientConfig {
|
|
|
495
503
|
- `setKey(key)` - 更新 API Key
|
|
496
504
|
- `getKey()` - 获取当前 API Key
|
|
497
505
|
|
|
506
|
+
### 服务清单
|
|
507
|
+
|
|
508
|
+
- geocode - 地理编码服务
|
|
509
|
+
- `regeocode()` - 逆地理编码
|
|
510
|
+
- `geocode()` - 地理编码
|
|
511
|
+
- `batchRegeocode()` - 批量逆地理编码
|
|
512
|
+
- `batchGeocode()` - 批量地理编码
|
|
513
|
+
- route - 路径规划服务(V5)
|
|
514
|
+
- `driving()` - 驾车路径规划
|
|
515
|
+
- `walking()` - 步行路径规划
|
|
516
|
+
- `bicycling()` - 骑行路径规划
|
|
517
|
+
- `electricBike()` - 电动车路径规划
|
|
518
|
+
- `transit()` - 公交路径规划
|
|
519
|
+
- poi - POI 搜索
|
|
520
|
+
- `search()` - 关键字搜索
|
|
521
|
+
- `searchAround()` - 周边搜索
|
|
522
|
+
- `getDetail()` - 详情
|
|
523
|
+
- inputTips - 输入提示
|
|
524
|
+
- `getTips()` - 基础提示
|
|
525
|
+
- `getPOITips()` - POI 类型提示
|
|
526
|
+
- `getBusTips()` - 公交站点提示
|
|
527
|
+
- `getBuslineTips()` - 公交线路提示
|
|
528
|
+
|
|
498
529
|
### 逆地理编码参数详解
|
|
499
530
|
|
|
500
531
|
#### regeocode(location, options?)
|
|
@@ -615,17 +646,17 @@ try {
|
|
|
615
646
|
|
|
616
647
|
## 注意事项
|
|
617
648
|
|
|
618
|
-
1.
|
|
619
|
-
2.
|
|
620
|
-
3.
|
|
621
|
-
4.
|
|
622
|
-
5.
|
|
649
|
+
1. Key 类型:必须使用 Web 服务 Key(非 iOS/Android Key)
|
|
650
|
+
2. 初始化:建议在 `expo-gaode-map` 或 `expo-gaode-map-navigation` 中通过 `initSDK({ webKey })` 下发,随后本包可无参构造
|
|
651
|
+
3. 配额限制:请参考高德控制台额度与 QPS 限制
|
|
652
|
+
4. 坐标格式:经度在前,纬度在后(经度,纬度)
|
|
653
|
+
5. 网络请求:需要网络连接,无法离线使用;Web 端可能遇到跨域,建议代理或服务端请求
|
|
623
654
|
|
|
624
655
|
## 相关资源
|
|
625
656
|
|
|
626
|
-
-
|
|
627
|
-
-
|
|
628
|
-
-
|
|
657
|
+
- 高德地图 Web API 文档:https://lbs.amap.com/api/webservice/summary
|
|
658
|
+
- 导航一体化模块(推荐渲染地图并下发 key):`expo-gaode-map-navigation`
|
|
659
|
+
- 核心地图模块:`expo-gaode-map`
|
|
629
660
|
|
|
630
661
|
## License
|
|
631
662
|
|
package/package.json
CHANGED
package/package.json.backup
CHANGED