expo-gaode-map-web-api 2.0.6 → 2.0.8
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 +100 -1
- package/build/index.d.ts +3 -1
- package/build/index.js +6 -1
- package/build/services/POIService.d.ts +20 -1
- package/build/services/POIService.js +29 -0
- package/build/types/poi.types.d.ts +79 -0
- package/build/utils/client.d.ts +1 -1
- package/build/utils/normalizers.d.ts +23 -0
- package/build/utils/normalizers.js +82 -0
- package/package.json +9 -2
package/README.md
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
- ✅ 公交(含多策略、跨城、地铁图模式、出入口等)
|
|
24
24
|
- 搜索服务
|
|
25
25
|
- ✅ POI 搜索(关键字、周边、类型、详情)
|
|
26
|
+
- ✅ AOI 边界查询(需开通高阶服务权限)
|
|
26
27
|
- ✅ 输入提示(POI/公交站点/公交线路)
|
|
27
28
|
|
|
28
29
|
## 安装
|
|
@@ -83,6 +84,18 @@ import { GaodeWebAPI } from 'expo-gaode-map-web-api';
|
|
|
83
84
|
const api = new GaodeWebAPI({ key: 'your-web-api-key' });
|
|
84
85
|
```
|
|
85
86
|
|
|
87
|
+
### Web API Key 解析顺序
|
|
88
|
+
|
|
89
|
+
`GaodeWebAPI` 会按以下顺序解析 Web API Key:
|
|
90
|
+
|
|
91
|
+
1. `new GaodeWebAPI({ key })` 中显式传入的 `key`
|
|
92
|
+
2. `expo-gaode-map` 的 `ExpoGaodeMapModule.initSDK({ webKey })`
|
|
93
|
+
3. `expo-gaode-map-navigation` 的 `ExpoGaodeMapModule.initSDK({ webKey })`
|
|
94
|
+
|
|
95
|
+
如果都没有提供,会直接抛出明确错误。
|
|
96
|
+
|
|
97
|
+
如果你的业务需要稳定使用 Web API,推荐显式传入 `key`,尤其是在示例工程、测试环境或多入口初始化场景里。
|
|
98
|
+
|
|
86
99
|
### 4. 调用服务接口
|
|
87
100
|
```ts
|
|
88
101
|
// 逆地理编码:坐标 → 地址
|
|
@@ -98,10 +111,96 @@ const route = await api.route.driving('116.481028,39.989643', '116.434446,39.908
|
|
|
98
111
|
show_fields: 'cost,navi,polyline',
|
|
99
112
|
});
|
|
100
113
|
console.log(route.route.paths[0].distance);
|
|
114
|
+
|
|
115
|
+
// AOI 边界查询(需开通权限)
|
|
116
|
+
const aoi = await api.poi.getAOIBoundary('your-aoi-id');
|
|
117
|
+
console.log(Array.isArray(aoi.aois) ? aoi.aois[0]?.polyline : aoi.aois?.polyline);
|
|
101
118
|
```
|
|
102
119
|
|
|
103
120
|
## 详细用法
|
|
104
121
|
|
|
122
|
+
### AOI 边界查询
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
const result = await api.poi.getAOIBoundary('your-aoi-id');
|
|
126
|
+
|
|
127
|
+
const aoi = Array.isArray(result.aois) ? result.aois[0] : result.aois;
|
|
128
|
+
console.log(aoi?.name);
|
|
129
|
+
console.log(aoi?.polyline);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
注意:
|
|
133
|
+
|
|
134
|
+
- `AOI 边界查询` 是高德 Web 服务里的高阶能力,正式使用前通常需要额外开通权限。
|
|
135
|
+
- 返回的 `polyline` 通常是 `lng,lat;lng,lat;...`,多环场景下可能为 `ring1|ring2`。
|
|
136
|
+
|
|
137
|
+
## 路线 / AOI 数据适配工具
|
|
138
|
+
|
|
139
|
+
为了让 Web API 的返回值能直接喂给 `expo-gaode-map` / `expo-gaode-map-navigation` 的用户层地图 API,本包额外提供了几个纯数据适配工具。
|
|
140
|
+
|
|
141
|
+
### extractRoutePoints(routeResult)
|
|
142
|
+
|
|
143
|
+
将驾车 / 步行 / 骑行 / 电动车结果中的 `steps.polyline` 摊平成一条连续点集:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
import { extractRoutePoints } from 'expo-gaode-map-web-api';
|
|
147
|
+
|
|
148
|
+
const result = await api.route.driving(origin, destination, {
|
|
149
|
+
show_fields: 'polyline,cost',
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const points = extractRoutePoints(result);
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### normalizeDrivingRoute(routeResult)
|
|
156
|
+
|
|
157
|
+
将驾车结果归一化为:
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
interface NormalizedDrivingRoute {
|
|
161
|
+
distance: number;
|
|
162
|
+
duration: number;
|
|
163
|
+
taxiCost?: number;
|
|
164
|
+
points: RoutePoint[];
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### extractAOIBoundary(aoiResult)
|
|
169
|
+
|
|
170
|
+
将 AOI 查询结果统一转成:
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
interface ExtractedAOIBoundary {
|
|
174
|
+
id?: string;
|
|
175
|
+
name?: string;
|
|
176
|
+
rings: RoutePoint[][];
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### extractTransitRoutePoints(transitResult)
|
|
181
|
+
|
|
182
|
+
将公交换乘结果提取为“每条换乘方案对应一条完整点集”:
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
const lines = extractTransitRoutePoints(transitResult);
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### 配合地图组件使用
|
|
189
|
+
|
|
190
|
+
```tsx
|
|
191
|
+
const routeResult = await api.route.driving(origin, destination, {
|
|
192
|
+
show_fields: 'polyline,cost',
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const points = extractRoutePoints(routeResult);
|
|
196
|
+
|
|
197
|
+
await mapRef.current?.fitToCoordinates(points, { duration: 500 });
|
|
198
|
+
|
|
199
|
+
<RouteOverlay points={points} />
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
这些适配结果可以同时用于 `core` 和 `navigation` 两套地图实现;共享的是数据结构,不是底层地图实现。
|
|
203
|
+
|
|
105
204
|
### 逆地理编码
|
|
106
205
|
|
|
107
206
|
#### 基础用法
|
|
@@ -539,6 +638,7 @@ interface ClientConfig {
|
|
|
539
638
|
- `search()` - 关键字搜索
|
|
540
639
|
- `searchAround()` - 周边搜索
|
|
541
640
|
- `getDetail()` - 详情
|
|
641
|
+
- `getAOIBoundary()` - AOI 边界查询
|
|
542
642
|
- inputTips - 输入提示
|
|
543
643
|
- `getTips()` - 基础提示
|
|
544
644
|
- `getPOITips()` - POI 类型提示
|
|
@@ -688,4 +788,3 @@ try {
|
|
|
688
788
|
## License
|
|
689
789
|
|
|
690
790
|
MIT License
|
|
691
|
-
|
package/build/index.d.ts
CHANGED
|
@@ -44,11 +44,13 @@ import { InputTipsService } from './services/InputTipsService';
|
|
|
44
44
|
export * from './types/geocode.types';
|
|
45
45
|
export * from './types/route.types';
|
|
46
46
|
export * from './types/inputtips.types';
|
|
47
|
-
export type { POISearchParams, POIAroundParams, POIPolygonParams, POIDetailParams, POIInfo, POISearchResponse, } from './types/poi.types';
|
|
47
|
+
export type { AOIBoundaryInfo, AOIBoundaryParams, AOIBoundaryResponse, POISearchParams, POIAroundParams, POIPolygonParams, POIDetailParams, POIInfo, POISearchResponse, } from './types/poi.types';
|
|
48
48
|
export type { ClientConfig, APIError } from './utils/client';
|
|
49
49
|
export { GaodeAPIError } from './utils/client';
|
|
50
50
|
export { getErrorInfo, isSuccess, ERROR_CODE_MAP } from './utils/errorCodes';
|
|
51
51
|
export type { InfoCode, ErrorInfo } from './utils/errorCodes';
|
|
52
|
+
export { extractAOIBoundary, extractRoutePoints, extractTransitRoutePoints, normalizeDrivingRoute, } from './utils/normalizers';
|
|
53
|
+
export type { ExtractedAOIBoundary, NormalizedDrivingRoute, RoutePoint, } from './utils/normalizers';
|
|
52
54
|
/**
|
|
53
55
|
* 高德地图 Web API 主类
|
|
54
56
|
*/
|
package/build/index.js
CHANGED
|
@@ -52,7 +52,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
52
52
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
53
53
|
};
|
|
54
54
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
-
exports.GaodeWebAPI = exports.ERROR_CODE_MAP = exports.isSuccess = exports.getErrorInfo = exports.GaodeAPIError = void 0;
|
|
55
|
+
exports.GaodeWebAPI = exports.normalizeDrivingRoute = exports.extractTransitRoutePoints = exports.extractRoutePoints = exports.extractAOIBoundary = exports.ERROR_CODE_MAP = exports.isSuccess = exports.getErrorInfo = exports.GaodeAPIError = void 0;
|
|
56
56
|
/**
|
|
57
57
|
* 在加载 Web API 模块前,强制校验“基础地图提供者”是否已安装。
|
|
58
58
|
* 支持以下任一包:
|
|
@@ -132,6 +132,11 @@ var errorCodes_1 = require("./utils/errorCodes");
|
|
|
132
132
|
Object.defineProperty(exports, "getErrorInfo", { enumerable: true, get: function () { return errorCodes_1.getErrorInfo; } });
|
|
133
133
|
Object.defineProperty(exports, "isSuccess", { enumerable: true, get: function () { return errorCodes_1.isSuccess; } });
|
|
134
134
|
Object.defineProperty(exports, "ERROR_CODE_MAP", { enumerable: true, get: function () { return errorCodes_1.ERROR_CODE_MAP; } });
|
|
135
|
+
var normalizers_1 = require("./utils/normalizers");
|
|
136
|
+
Object.defineProperty(exports, "extractAOIBoundary", { enumerable: true, get: function () { return normalizers_1.extractAOIBoundary; } });
|
|
137
|
+
Object.defineProperty(exports, "extractRoutePoints", { enumerable: true, get: function () { return normalizers_1.extractRoutePoints; } });
|
|
138
|
+
Object.defineProperty(exports, "extractTransitRoutePoints", { enumerable: true, get: function () { return normalizers_1.extractTransitRoutePoints; } });
|
|
139
|
+
Object.defineProperty(exports, "normalizeDrivingRoute", { enumerable: true, get: function () { return normalizers_1.normalizeDrivingRoute; } });
|
|
135
140
|
/**
|
|
136
141
|
* 高德地图 Web API 主类
|
|
137
142
|
*/
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* 高德地图 Web API - POI 搜索服务
|
|
3
3
|
*/
|
|
4
4
|
import { GaodeWebAPIClient } from '../utils/client';
|
|
5
|
-
import type { POISearchParams, POIAroundParams, POIPolygonParams, POISearchResponse } from '../types/poi.types';
|
|
5
|
+
import type { AOIBoundaryParams, AOIBoundaryResponse, POISearchParams, POIAroundParams, POIPolygonParams, POISearchResponse } from '../types/poi.types';
|
|
6
6
|
/**
|
|
7
7
|
* POI 搜索服务
|
|
8
8
|
*/
|
|
@@ -134,4 +134,23 @@ export declare class POIService {
|
|
|
134
134
|
batchGetDetail(ids: string[], show_fields?: string, version?: 'v3' | 'v5', options?: {
|
|
135
135
|
signal?: AbortSignal;
|
|
136
136
|
}): Promise<POISearchResponse>;
|
|
137
|
+
/**
|
|
138
|
+
* AOI 边界查询
|
|
139
|
+
* 根据 AOI ID 获取其边界 polyline。
|
|
140
|
+
*
|
|
141
|
+
* 注意:该接口属于高阶服务,通常需要先在高德开放平台开通权限。
|
|
142
|
+
*
|
|
143
|
+
* @param id AOI ID
|
|
144
|
+
* @param options 可选参数
|
|
145
|
+
* @returns AOI 边界查询结果
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const result = await api.poi.getAOIBoundary('aoi-id');
|
|
150
|
+
*
|
|
151
|
+
* const aoi = Array.isArray(result.aois) ? result.aois[0] : result.aois;
|
|
152
|
+
* console.log(aoi?.polyline);
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
getAOIBoundary(id: string, options?: Omit<AOIBoundaryParams, 'id'>): Promise<AOIBoundaryResponse>;
|
|
137
156
|
}
|
|
@@ -182,5 +182,34 @@ class POIService {
|
|
|
182
182
|
const path = `/${version}/place/detail`;
|
|
183
183
|
return this.client.request(path, { params, signal: options?.signal });
|
|
184
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* AOI 边界查询
|
|
187
|
+
* 根据 AOI ID 获取其边界 polyline。
|
|
188
|
+
*
|
|
189
|
+
* 注意:该接口属于高阶服务,通常需要先在高德开放平台开通权限。
|
|
190
|
+
*
|
|
191
|
+
* @param id AOI ID
|
|
192
|
+
* @param options 可选参数
|
|
193
|
+
* @returns AOI 边界查询结果
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* const result = await api.poi.getAOIBoundary('aoi-id');
|
|
198
|
+
*
|
|
199
|
+
* const aoi = Array.isArray(result.aois) ? result.aois[0] : result.aois;
|
|
200
|
+
* console.log(aoi?.polyline);
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
async getAOIBoundary(id, options) {
|
|
204
|
+
const { signal, ...rest } = options || {};
|
|
205
|
+
const params = {
|
|
206
|
+
id,
|
|
207
|
+
...rest,
|
|
208
|
+
};
|
|
209
|
+
return this.client.request('/v5/aoi/polyline', {
|
|
210
|
+
params,
|
|
211
|
+
signal,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
185
214
|
}
|
|
186
215
|
exports.POIService = POIService;
|
|
@@ -353,3 +353,82 @@ export interface POIDetailParams {
|
|
|
353
353
|
*/
|
|
354
354
|
signal?: AbortSignal;
|
|
355
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* AOI 边界查询参数
|
|
358
|
+
*
|
|
359
|
+
* 注意:该接口属于高阶服务,通常需要单独开通权限后才能正常使用。
|
|
360
|
+
*/
|
|
361
|
+
export interface AOIBoundaryParams {
|
|
362
|
+
/**
|
|
363
|
+
* AOI 唯一标识
|
|
364
|
+
*/
|
|
365
|
+
id: string;
|
|
366
|
+
/**
|
|
367
|
+
* 数字签名
|
|
368
|
+
*/
|
|
369
|
+
sig?: string;
|
|
370
|
+
/**
|
|
371
|
+
* JSONP 回调函数名
|
|
372
|
+
*/
|
|
373
|
+
callback?: string;
|
|
374
|
+
/**
|
|
375
|
+
* 透传扩展参数
|
|
376
|
+
*/
|
|
377
|
+
parameters?: string;
|
|
378
|
+
/**
|
|
379
|
+
* AbortSignal 用于取消请求
|
|
380
|
+
*/
|
|
381
|
+
signal?: AbortSignal;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* AOI 边界信息
|
|
385
|
+
*/
|
|
386
|
+
export interface AOIBoundaryInfo {
|
|
387
|
+
/** AOI 名称 */
|
|
388
|
+
name?: string;
|
|
389
|
+
/** AOI 唯一标识 */
|
|
390
|
+
id?: string;
|
|
391
|
+
/** AOI 中心点坐标,格式:经度,纬度 */
|
|
392
|
+
location?: string;
|
|
393
|
+
/**
|
|
394
|
+
* AOI 边界串
|
|
395
|
+
* 通常格式为:
|
|
396
|
+
* - 单环:lng,lat;lng,lat;...
|
|
397
|
+
* - 多环:ring1|ring2
|
|
398
|
+
*/
|
|
399
|
+
polyline?: string;
|
|
400
|
+
/** AOI 所属分类 */
|
|
401
|
+
type?: string;
|
|
402
|
+
/** AOI 分类编码 */
|
|
403
|
+
typecode?: string;
|
|
404
|
+
/** AOI 所属省份 */
|
|
405
|
+
pname?: string;
|
|
406
|
+
/** AOI 所属城市 */
|
|
407
|
+
cityname?: string;
|
|
408
|
+
/** AOI 所属区域 */
|
|
409
|
+
adname?: string;
|
|
410
|
+
/** AOI 详细地址 */
|
|
411
|
+
address?: string;
|
|
412
|
+
/** AOI 所属省份编码 */
|
|
413
|
+
pcode?: string;
|
|
414
|
+
/** AOI 所属城市编码 */
|
|
415
|
+
citycode?: string;
|
|
416
|
+
/** AOI 所属区域编码 */
|
|
417
|
+
adcode?: string;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* AOI 边界查询响应
|
|
421
|
+
*
|
|
422
|
+
* 官方文档字段名为 `aois`,但多数场景只返回单个 AOI 对象;
|
|
423
|
+
* 这里兼容单对象和数组两种结构,避免调用方被接口细节卡住。
|
|
424
|
+
*/
|
|
425
|
+
export interface AOIBoundaryResponse {
|
|
426
|
+
/** 返回状态 */
|
|
427
|
+
status: string;
|
|
428
|
+
/** 返回的状态信息 */
|
|
429
|
+
info: string;
|
|
430
|
+
/** 状态码 */
|
|
431
|
+
infocode: string;
|
|
432
|
+
/** AOI 边界结果 */
|
|
433
|
+
aois?: AOIBoundaryInfo | AOIBoundaryInfo[];
|
|
434
|
+
}
|
package/build/utils/client.d.ts
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { BicyclingRouteResponse, DrivingRouteResponse, ElectricBikeRouteResponse, TransitRouteResponse, WalkingRouteResponse } from '../types/route.types';
|
|
2
|
+
import type { AOIBoundaryResponse } from '../types/poi.types';
|
|
3
|
+
export interface RoutePoint {
|
|
4
|
+
latitude: number;
|
|
5
|
+
longitude: number;
|
|
6
|
+
}
|
|
7
|
+
export interface NormalizedDrivingRoute {
|
|
8
|
+
distance: number;
|
|
9
|
+
duration: number;
|
|
10
|
+
taxiCost?: number;
|
|
11
|
+
points: RoutePoint[];
|
|
12
|
+
}
|
|
13
|
+
export interface ExtractedAOIBoundary {
|
|
14
|
+
id?: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
rings: RoutePoint[][];
|
|
17
|
+
}
|
|
18
|
+
type SupportedRouteResponse = DrivingRouteResponse | WalkingRouteResponse | BicyclingRouteResponse | ElectricBikeRouteResponse;
|
|
19
|
+
export declare function extractRoutePoints(routeResult: SupportedRouteResponse): RoutePoint[];
|
|
20
|
+
export declare function normalizeDrivingRoute(routeResult: DrivingRouteResponse): NormalizedDrivingRoute;
|
|
21
|
+
export declare function extractAOIBoundary(aoiResult: AOIBoundaryResponse): ExtractedAOIBoundary;
|
|
22
|
+
export declare function extractTransitRoutePoints(transitResult: TransitRouteResponse): RoutePoint[][];
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractRoutePoints = extractRoutePoints;
|
|
4
|
+
exports.normalizeDrivingRoute = normalizeDrivingRoute;
|
|
5
|
+
exports.extractAOIBoundary = extractAOIBoundary;
|
|
6
|
+
exports.extractTransitRoutePoints = extractTransitRoutePoints;
|
|
7
|
+
function parsePolyline(polyline) {
|
|
8
|
+
if (!polyline?.trim()) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
return polyline
|
|
12
|
+
.split(';')
|
|
13
|
+
.map((segment) => segment.trim())
|
|
14
|
+
.filter(Boolean)
|
|
15
|
+
.map((segment) => {
|
|
16
|
+
const [longitude, latitude] = segment.split(',').map((value) => Number(value.trim()));
|
|
17
|
+
if (!Number.isFinite(longitude) || !Number.isFinite(latitude)) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
latitude,
|
|
22
|
+
longitude,
|
|
23
|
+
};
|
|
24
|
+
})
|
|
25
|
+
.filter((point) => point !== null);
|
|
26
|
+
}
|
|
27
|
+
function dedupeAdjacentPoints(points) {
|
|
28
|
+
return points.filter((point, index) => {
|
|
29
|
+
if (index === 0) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
const previous = points[index - 1];
|
|
33
|
+
return (previous.latitude !== point.latitude ||
|
|
34
|
+
previous.longitude !== point.longitude);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function extractStepPoints(steps = []) {
|
|
38
|
+
return dedupeAdjacentPoints(steps.flatMap((step) => parsePolyline(step.polyline)));
|
|
39
|
+
}
|
|
40
|
+
function extractRoutePoints(routeResult) {
|
|
41
|
+
// 将 Web API 的 steps.polyline 摊平成地图组件可直接消费的点集。
|
|
42
|
+
const firstPath = routeResult.route?.paths?.[0];
|
|
43
|
+
if (!firstPath) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
return extractStepPoints(firstPath.steps);
|
|
47
|
+
}
|
|
48
|
+
function normalizeDrivingRoute(routeResult) {
|
|
49
|
+
// 为常见“路径预览 / 地图绘制”场景提供一个更扁平的数据结构,
|
|
50
|
+
// 业务层不必再自己处理字符串数字和嵌套字段。
|
|
51
|
+
const firstPath = routeResult.route?.paths?.[0];
|
|
52
|
+
return {
|
|
53
|
+
distance: Number(firstPath?.distance ?? 0),
|
|
54
|
+
duration: Number(firstPath?.cost?.duration ?? firstPath?.duration ?? 0),
|
|
55
|
+
taxiCost: routeResult.route?.taxi_cost ? Number(routeResult.route.taxi_cost) : undefined,
|
|
56
|
+
points: extractRoutePoints(routeResult),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function extractAOIBoundary(aoiResult) {
|
|
60
|
+
// AOI 边界返回值可能是单对象,也可能是数组;
|
|
61
|
+
// 这里统一归一成 { id, name, rings } 结构。
|
|
62
|
+
const aoi = Array.isArray(aoiResult.aois) ? aoiResult.aois[0] : aoiResult.aois;
|
|
63
|
+
const polyline = aoi?.polyline ?? '';
|
|
64
|
+
const rings = polyline
|
|
65
|
+
.split('|')
|
|
66
|
+
.map((ring) => parsePolyline(ring))
|
|
67
|
+
.filter((ring) => ring.length > 0);
|
|
68
|
+
return {
|
|
69
|
+
id: aoi?.id,
|
|
70
|
+
name: aoi?.name,
|
|
71
|
+
rings,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function extractTransitRoutePoints(transitResult) {
|
|
75
|
+
// 公交换乘路线会混合步行段、公交段、铁路段,
|
|
76
|
+
// 这里统一抽成“每条换乘方案 -> 一条完整点集”。
|
|
77
|
+
return (transitResult.route?.transits ?? []).map((transit) => dedupeAdjacentPoints(transit.segments.flatMap((segment) => [
|
|
78
|
+
...(segment.walking ? extractStepPoints(segment.walking.steps) : []),
|
|
79
|
+
...(segment.bus?.buslines?.flatMap((line) => parsePolyline(line.polyline)) ?? []),
|
|
80
|
+
...(segment.railway?.buslines?.flatMap((line) => parsePolyline(line.polyline)) ?? []),
|
|
81
|
+
])));
|
|
82
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-gaode-map-web-api",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.8",
|
|
4
|
+
"description": "AMap (Gaode Map) Web API toolkit for Expo/React Native: search, geocoding, and route planning in pure JavaScript.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -19,11 +19,18 @@
|
|
|
19
19
|
"keywords": [
|
|
20
20
|
"react-native",
|
|
21
21
|
"expo",
|
|
22
|
+
"expo-gaode-map-web-api",
|
|
23
|
+
"expo-amap",
|
|
24
|
+
"react-native-amap",
|
|
25
|
+
"react-native-gaode-map",
|
|
22
26
|
"amap",
|
|
23
27
|
"gaode",
|
|
28
|
+
"gaode-map",
|
|
24
29
|
"web-api",
|
|
25
30
|
"search",
|
|
26
31
|
"geocode",
|
|
32
|
+
"geocoding",
|
|
33
|
+
"route-planning",
|
|
27
34
|
"route",
|
|
28
35
|
"高德地图"
|
|
29
36
|
],
|