expo-gaode-map-navigation 1.1.5-next.0 → 1.1.5-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 +213 -73
- package/android/src/main/java/expo/modules/gaodemap/navigation/ExpoGaodeMapNaviView.kt +13 -3
- package/android/src/main/java/expo/modules/gaodemap/navigation/ExpoGaodeMapNaviViewModule.kt +4 -0
- package/build/ExpoGaodeMapNaviView.js +2 -3
- package/build/map/ExpoGaodeMapModule.js +4 -6
- package/build/map/utils/EventManager.js +1 -1
- package/build/types/naviview.types.d.ts +5 -0
- package/ios/map/modules/LocationManager.swift +9 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,62 +1,68 @@
|
|
|
1
1
|
# expo-gaode-map-navigation
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
高德地图“导航一体化”模块。内置地图渲染能力与导航能力,提供从地图展示到路径规划、实时导航的完整解决方案。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 特性
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- 🗺️ 地图渲染:内置地图视图与常用覆盖物(标注、折线、多边形、热力图、聚合等)
|
|
14
|
-
- 🧭 路径与导航:驾车、步行、骑行等多种出行策略与实时引导
|
|
15
|
-
- ⚙️ 策略丰富:最快、最短、避拥堵、少收费、少红绿灯等
|
|
16
|
-
- 🚗 复杂路线:支持多途经点、限行考虑、分段规划
|
|
17
|
-
- 🌐 Web API 协作:可与 `expo-gaode-map-web-api` 配合,统一通过基础初始化下发 Web Key 后使用
|
|
7
|
+
- 🗺️ **地图渲染**:内置完整地图能力,支持 Marker、Polyline、Polygon、Circle、Cluster、HeatMap 等覆盖物。
|
|
8
|
+
- 🚗 **多模式路径规划**:支持驾车、步行、骑行、电动车、货车、摩托车等多种出行方式。
|
|
9
|
+
- 🧭 **实时导航 UI**:提供 `NaviView` 组件,内置完整的导航界面、语音播报、转向指引、路况显示等。
|
|
10
|
+
- 🛣️ **独立路径规划**:支持“先算路、再导航”的高级模式,可实现多路线对比与选择。
|
|
11
|
+
- ⚙️ **策略丰富**:支持速度优先、避让拥堵、少收费、不走高速等多种算路策略。
|
|
12
|
+
- � **开箱即用**:封装了 Android/iOS 原生导航 SDK,统一 JS 接口。
|
|
18
13
|
|
|
19
14
|
## 安装
|
|
20
15
|
|
|
21
|
-
|
|
16
|
+
本模块已包含地图与导航的所有能力,**不需要**、也不应同时安装 `expo-gaode-map`。
|
|
22
17
|
|
|
23
18
|
```bash
|
|
24
19
|
# bun
|
|
25
20
|
bun add expo-gaode-map-navigation
|
|
26
21
|
|
|
27
|
-
#
|
|
22
|
+
# yarn
|
|
28
23
|
yarn add expo-gaode-map-navigation
|
|
29
24
|
|
|
25
|
+
# npm
|
|
26
|
+
npm install expo-gaode-map-navigation
|
|
30
27
|
```
|
|
31
28
|
|
|
32
|
-
|
|
29
|
+
**⚠️ 重要提示:**
|
|
30
|
+
如果项目中已安装 `expo-gaode-map`,请务必先卸载,否则会导致 Android 端二进制冲突(`3dmap` vs `navi-3dmap`)。`expo-gaode-map` 和 `expo-gaode-map-navigation` 由于 SDK 冲突不能同时安装,二选一使用。
|
|
33
31
|
|
|
34
|
-
```bash
|
|
35
|
-
npm uninstall expo-gaode-map
|
|
36
|
-
# or: yarn remove expo-gaode-map
|
|
37
|
-
# or: bun remove expo-gaode-map
|
|
38
|
-
```
|
|
39
32
|
|
|
40
|
-
|
|
33
|
+
### Config Plugin 配置(推荐)
|
|
41
34
|
|
|
42
|
-
|
|
35
|
+
在 `app.json` 中配置,自动设置原生 API Key 和权限:
|
|
43
36
|
|
|
44
|
-
```
|
|
45
|
-
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"expo": {
|
|
40
|
+
"plugins": [
|
|
41
|
+
[
|
|
42
|
+
"expo-gaode-map-navigation",
|
|
43
|
+
{
|
|
44
|
+
"androidKey": "your-android-key",
|
|
45
|
+
"iosKey": "your-ios-key"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
配置后重新构建:
|
|
46
53
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
54
|
+
```bash
|
|
55
|
+
npx expo prebuild --clean
|
|
56
|
+
npx expo run:android
|
|
57
|
+
npx expo run:ios
|
|
52
58
|
```
|
|
53
59
|
|
|
54
|
-
说明:
|
|
55
|
-
- 如后续使用 `expo-gaode-map-web-api`,建议同时传入 `webKey`,该包会从本模块运行时读取 `webKey`,实现“无参构造”的简化用法(new GaodeWebAPI())。
|
|
56
60
|
|
|
57
|
-
##
|
|
61
|
+
## 快速开始
|
|
62
|
+
|
|
63
|
+
### 1. 显示地图
|
|
58
64
|
|
|
59
|
-
|
|
65
|
+
使用内置的 `MapView` 组件显示地图:
|
|
60
66
|
|
|
61
67
|
```tsx
|
|
62
68
|
import React from 'react';
|
|
@@ -70,13 +76,12 @@ export default function BasicMapScreen() {
|
|
|
70
76
|
style={{ flex: 1 }}
|
|
71
77
|
initialCameraPosition={{
|
|
72
78
|
target: { latitude: 39.909186, longitude: 116.397411 },
|
|
73
|
-
zoom:
|
|
79
|
+
zoom: 15,
|
|
74
80
|
}}
|
|
75
81
|
>
|
|
76
82
|
<Marker
|
|
77
83
|
position={{ latitude: 39.909186, longitude: 116.397411 }}
|
|
78
84
|
title="天安门"
|
|
79
|
-
snippet="北京·东城区"
|
|
80
85
|
/>
|
|
81
86
|
</MapView>
|
|
82
87
|
</View>
|
|
@@ -84,69 +89,204 @@ export default function BasicMapScreen() {
|
|
|
84
89
|
}
|
|
85
90
|
```
|
|
86
91
|
|
|
87
|
-
|
|
92
|
+
### 2. 嵌入导航视图
|
|
88
93
|
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
使用 `NaviView` 组件直接嵌入导航界面:
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
import React, { useEffect, useRef } from 'react';
|
|
98
|
+
import { View } from 'react-native';
|
|
99
|
+
import { NaviView, type NaviViewRef } from 'expo-gaode-map-navigation';
|
|
100
|
+
|
|
101
|
+
export default function NavigationScreen() {
|
|
102
|
+
const naviRef = useRef<NaviViewRef>(null);
|
|
103
|
+
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
// 延迟 1 秒后开始导航
|
|
106
|
+
const timer = setTimeout(() => {
|
|
107
|
+
if (naviRef.current) {
|
|
108
|
+
naviRef.current.startNavigation(
|
|
109
|
+
{ latitude: 39.909186, longitude: 116.397411 }, // 起点
|
|
110
|
+
{ latitude: 39.99, longitude: 116.47 }, // 终点
|
|
111
|
+
0 // 0: GPS导航, 1: 模拟导航
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}, 1000);
|
|
115
|
+
return () => clearTimeout(timer);
|
|
116
|
+
}, []);
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<View style={{ flex: 1 }}>
|
|
120
|
+
<NaviView
|
|
121
|
+
ref={naviRef}
|
|
122
|
+
style={{ flex: 1 }}
|
|
123
|
+
showCamera={true} // 显示摄像头
|
|
124
|
+
enableVoice={true} // 开启语音
|
|
125
|
+
/>
|
|
126
|
+
</View>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## 详细用法
|
|
132
|
+
|
|
133
|
+
### 路径规划 (API)
|
|
134
|
+
|
|
135
|
+
使用 `calculateRoute` 方法进行路径计算,不涉及 UI 显示,适合用于获取距离、时间或绘制路线。
|
|
136
|
+
|
|
137
|
+
#### 驾车路径规划
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { calculateRoute, RouteType, DriveStrategy } from 'expo-gaode-map-navigation';
|
|
91
141
|
|
|
92
142
|
const result = await calculateRoute({
|
|
93
|
-
type:
|
|
143
|
+
type: RouteType.DRIVE,
|
|
94
144
|
from: { latitude: 39.9, longitude: 116.4 },
|
|
95
145
|
to: { latitude: 39.91, longitude: 116.41 },
|
|
96
|
-
strategy: DriveStrategy.FASTEST,
|
|
146
|
+
strategy: DriveStrategy.FASTEST, // 速度优先
|
|
147
|
+
avoidRoad: '京通快速路', // 避让道路名称
|
|
97
148
|
});
|
|
98
149
|
|
|
99
|
-
|
|
150
|
+
console.log(`总距离: ${result.routes[0].distance}米`);
|
|
151
|
+
console.log(`预计耗时: ${result.routes[0].duration}秒`);
|
|
100
152
|
```
|
|
101
153
|
|
|
102
|
-
|
|
103
|
-
- 地图组件与导航能力均来自 `expo-gaode-map-navigation`,无需、也不应从 `expo-gaode-map` 引入任何 API。
|
|
154
|
+
#### 步行/骑行路径规划
|
|
104
155
|
|
|
105
|
-
|
|
156
|
+
```typescript
|
|
157
|
+
import { calculateRoute, RouteType, RideStrategy } from 'expo-gaode-map-navigation';
|
|
106
158
|
|
|
107
|
-
|
|
159
|
+
// 骑行
|
|
160
|
+
const rideResult = await calculateRoute({
|
|
161
|
+
type: RouteType.RIDE,
|
|
162
|
+
from: { latitude: 39.9, longitude: 116.4 },
|
|
163
|
+
to: { latitude: 39.91, longitude: 116.41 },
|
|
164
|
+
strategy: RideStrategy.FASTEST,
|
|
165
|
+
});
|
|
108
166
|
|
|
109
|
-
|
|
110
|
-
|
|
167
|
+
// 步行
|
|
168
|
+
const walkResult = await calculateRoute({
|
|
169
|
+
type: RouteType.WALK,
|
|
170
|
+
from: { latitude: 39.9, longitude: 116.4 },
|
|
171
|
+
to: { latitude: 39.91, longitude: 116.41 },
|
|
172
|
+
multiple: true, // 返回多条路线
|
|
173
|
+
});
|
|
174
|
+
```
|
|
111
175
|
|
|
112
|
-
|
|
113
|
-
```ts
|
|
114
|
-
import { calculateRoute, DriveStrategy } from 'expo-gaode-map-navigation';
|
|
176
|
+
#### 货车路径规划
|
|
115
177
|
|
|
116
|
-
|
|
117
|
-
|
|
178
|
+
```typescript
|
|
179
|
+
import { calculateRoute, RouteType, TruckSize } from 'expo-gaode-map-navigation';
|
|
180
|
+
|
|
181
|
+
const truckResult = await calculateRoute({
|
|
182
|
+
type: RouteType.TRUCK,
|
|
118
183
|
from: { latitude: 39.9, longitude: 116.4 },
|
|
119
184
|
to: { latitude: 39.91, longitude: 116.41 },
|
|
120
|
-
|
|
185
|
+
size: TruckSize.MEDIUM, // 中型货车
|
|
186
|
+
height: 3.5, // 高度 3.5m
|
|
187
|
+
load: 10, // 载重 10吨
|
|
121
188
|
});
|
|
122
|
-
|
|
123
|
-
// result 包含距离/时长/分步指引等原生返回
|
|
124
189
|
```
|
|
125
190
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
191
|
+
### 独立路径规划 (Advanced)
|
|
192
|
+
|
|
193
|
+
“独立路径规划”允许你先计算路线,并在地图上展示多条方案,用户选择其中一条后再开始导航。这通常比直接开始导航体验更好。
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
import {
|
|
197
|
+
independentDriveRoute,
|
|
198
|
+
selectIndependentRoute,
|
|
199
|
+
startNaviWithIndependentPath,
|
|
200
|
+
DriveStrategy
|
|
201
|
+
} from 'expo-gaode-map-navigation';
|
|
202
|
+
|
|
203
|
+
// 1. 发起算路(不会自动开始导航)
|
|
204
|
+
const result = await independentDriveRoute({
|
|
205
|
+
from: { latitude: 39.9, longitude: 116.4 },
|
|
206
|
+
to: { latitude: 39.91, longitude: 116.41 },
|
|
207
|
+
strategy: DriveStrategy.AVOID_CONGESTION,
|
|
208
|
+
});
|
|
129
209
|
|
|
130
|
-
//
|
|
131
|
-
|
|
210
|
+
// 2. 选择某一条路线(例如 index=1 的路线)
|
|
211
|
+
// 这通常配合地图上的点击事件,高亮显示某条路线
|
|
212
|
+
await selectIndependentRoute({
|
|
213
|
+
routeId: result.routes[1].id
|
|
214
|
+
});
|
|
132
215
|
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
|
|
216
|
+
// 3. 使用当前选中的路线开始导航
|
|
217
|
+
await startNaviWithIndependentPath({
|
|
218
|
+
emulator: true, // 开启模拟导航
|
|
136
219
|
});
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### 地图组件 (Map)
|
|
137
223
|
|
|
138
|
-
|
|
224
|
+
模块导出了完整的地图组件,与 `expo-gaode-map` API 保持一致。
|
|
225
|
+
|
|
226
|
+
```tsx
|
|
227
|
+
import { MapView, Circle, Polygon } from 'expo-gaode-map-navigation';
|
|
228
|
+
|
|
229
|
+
<MapView style={{ flex: 1 }}>
|
|
230
|
+
{/* 圆形覆盖物 */}
|
|
231
|
+
<Circle
|
|
232
|
+
center={{ latitude: 39.9, longitude: 116.4 }}
|
|
233
|
+
radius={1000}
|
|
234
|
+
fillColor="rgba(0,0,255, 0.3)"
|
|
235
|
+
strokeColor="rgba(0,0,255, 0.5)"
|
|
236
|
+
/>
|
|
237
|
+
|
|
238
|
+
{/* 多边形 */}
|
|
239
|
+
<Polygon
|
|
240
|
+
points={[
|
|
241
|
+
{ latitude: 39.9, longitude: 116.4 },
|
|
242
|
+
{ latitude: 39.91, longitude: 116.41 },
|
|
243
|
+
{ latitude: 39.92, longitude: 116.42 },
|
|
244
|
+
]}
|
|
245
|
+
strokeWidth={2}
|
|
246
|
+
/>
|
|
247
|
+
</MapView>
|
|
139
248
|
```
|
|
140
249
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
250
|
+
## API 参考
|
|
251
|
+
|
|
252
|
+
### DriveStrategy (驾车策略)
|
|
253
|
+
|
|
254
|
+
| 值 | 说明 |
|
|
255
|
+
|---|---|
|
|
256
|
+
| `FASTEST` (0) | 速度优先(时间最短) |
|
|
257
|
+
| `FEE_FIRST` (1) | 费用优先(少收费) |
|
|
258
|
+
| `SHORTEST` (2) | 距离优先 |
|
|
259
|
+
| `NO_HIGHWAY` (5) | 不走高速 |
|
|
260
|
+
| `AVOID_CONGESTION` (4) | 躲避拥堵 |
|
|
261
|
+
| ... | 更多策略请参考类型定义 |
|
|
262
|
+
|
|
263
|
+
### NaviView Props
|
|
264
|
+
|
|
265
|
+
| 属性 | 类型 | 说明 |
|
|
266
|
+
|---|---|---|
|
|
267
|
+
| `naviType` | number | 导航类型(0: GPS, 1: 模拟) |
|
|
268
|
+
| `showCrossImage` | boolean | 是否显示路口放大图 |
|
|
269
|
+
| `showCamera` | boolean | 是否显示摄像头 |
|
|
270
|
+
| `showTrafficButton` | boolean | 是否显示路况按钮 |
|
|
271
|
+
| `enableVoice` | boolean | 是否开启语音播报 |
|
|
272
|
+
| `onArrive` | function | 到达目的地回调 |
|
|
273
|
+
| `onNaviInfoUpdate` | function | 导航信息更新(剩余距离、时间等) |
|
|
274
|
+
|
|
275
|
+
## 注意事项
|
|
276
|
+
|
|
277
|
+
1. **二进制冲突**:严禁与 `expo-gaode-map` 共存。本模块已包含 `3dmap` SDK。
|
|
278
|
+
2. **Web API**:如果需要更灵活的 HTTP 算路(如公交跨城规划、Web端展示),推荐配合 `expo-gaode-map-web-api` 使用。
|
|
279
|
+
3. **权限**:使用导航功能前,请确保应用已获取定位权限(`ACCESS_FINE_LOCATION`)。
|
|
280
|
+
|
|
144
281
|
|
|
145
|
-
##
|
|
282
|
+
## 📚 文档与资源
|
|
146
283
|
|
|
147
|
-
-
|
|
148
|
-
-
|
|
284
|
+
- [在线文档](https://tomwq.github.io/expo-gaode-map/api/navigation.html)
|
|
285
|
+
- [GitHub 仓库](https://github.com/TomWq/expo-gaode-map/packages/navigation)
|
|
286
|
+
- [示例项目(导航)](https://github.com/TomWq/expo-gaode-map-navigation-example)
|
|
287
|
+
- [高德地图开放平台](https://lbs.amap.com/)
|
|
288
|
+
- [Expo Modules API](https://docs.expo.dev/modules/overview/)
|
|
149
289
|
|
|
150
|
-
##
|
|
290
|
+
## License
|
|
151
291
|
|
|
152
|
-
MIT
|
|
292
|
+
MIT License
|
|
@@ -58,6 +58,7 @@ class ExpoGaodeMapNaviView(context: Context, appContext: AppContext) : ExpoView(
|
|
|
58
58
|
internal var isAfterRouteAutoGray: Boolean = false
|
|
59
59
|
internal var isVectorLineShow: Boolean = true
|
|
60
60
|
internal var isNaviTravelView : Boolean = false
|
|
61
|
+
internal var isCompassEnabled: Boolean = true
|
|
61
62
|
private val naviView: AMapNaviView = AMapNaviView(context)
|
|
62
63
|
private var aMapNavi: AMapNavi? = null
|
|
63
64
|
private var startCoordinate: NaviLatLng? = null
|
|
@@ -329,7 +330,7 @@ class ExpoGaodeMapNaviView(context: Context, appContext: AppContext) : ExpoView(
|
|
|
329
330
|
// 设置为 true 将显示导航信息面板(包括距离、时间等)
|
|
330
331
|
options.isLayoutVisible = showUIElements
|
|
331
332
|
options.isSettingMenuEnabled = true // 显示设置菜单按钮
|
|
332
|
-
options.isCompassEnabled =
|
|
333
|
+
options.isCompassEnabled = isCompassEnabled // 显示指南针
|
|
333
334
|
options.isTrafficBarEnabled = androidTrafficBarEnabled // 显示路况条
|
|
334
335
|
options.isRouteListButtonShow = isRouteListButtonShow // 显示路线全览按钮
|
|
335
336
|
|
|
@@ -843,7 +844,15 @@ class ExpoGaodeMapNaviView(context: Context, appContext: AppContext) : ExpoView(
|
|
|
843
844
|
options.isRealCrossDisplayShow = enabled
|
|
844
845
|
naviView.viewOptions = options
|
|
845
846
|
}
|
|
846
|
-
|
|
847
|
+
|
|
848
|
+
fun applyShowCompassEnabled(enabled: Boolean){
|
|
849
|
+
isCompassEnabled = enabled
|
|
850
|
+
val options = naviView.viewOptions
|
|
851
|
+
options.isCompassEnabled = enabled
|
|
852
|
+
naviView.viewOptions = options
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
|
|
847
856
|
fun applyNaviMode(mode: Int) {
|
|
848
857
|
// 0: 车头朝上 1: 正北朝上
|
|
849
858
|
naviView.naviMode = mode
|
|
@@ -884,7 +893,8 @@ class ExpoGaodeMapNaviView(context: Context, appContext: AppContext) : ExpoView(
|
|
|
884
893
|
Log.e("ExpoGaodeMapNaviView", "Failed to set car overlay visibility", e)
|
|
885
894
|
}
|
|
886
895
|
}
|
|
887
|
-
|
|
896
|
+
|
|
897
|
+
|
|
888
898
|
/**
|
|
889
899
|
* 设置是否显示交通信号灯
|
|
890
900
|
* @param visible true-显示 false-隐藏
|
package/android/src/main/java/expo/modules/gaodemap/navigation/ExpoGaodeMapNaviViewModule.kt
CHANGED
|
@@ -75,6 +75,10 @@ class ExpoGaodeMapNaviViewModule : Module() {
|
|
|
75
75
|
Prop<Boolean>("showTrafficLights") { view, visible ->
|
|
76
76
|
view.applyTrafficLightsVisible(visible)
|
|
77
77
|
}
|
|
78
|
+
|
|
79
|
+
Prop<Boolean>("showCompassEnabled") {view, enabled ->
|
|
80
|
+
view.applyShowCompassEnabled(enabled)
|
|
81
|
+
}
|
|
78
82
|
|
|
79
83
|
Prop<Map<String, Boolean>?>("routeMarkerVisible") { view, config ->
|
|
80
84
|
config?.let {
|
|
@@ -75,12 +75,11 @@ exports.NaviView = React.forwardRef((props, ref) => {
|
|
|
75
75
|
// 创建 API 引用
|
|
76
76
|
const apiRef = React.useMemo(() => ({
|
|
77
77
|
startNavigation: async (start, end, type) => {
|
|
78
|
-
var _a, _b;
|
|
79
78
|
if (!nativeRef.current)
|
|
80
79
|
throw new Error('NaviView not initialized');
|
|
81
80
|
// 将对象解构为单独的参数传递给原生层
|
|
82
|
-
const startLat =
|
|
83
|
-
const startLng =
|
|
81
|
+
const startLat = start?.latitude ?? 0;
|
|
82
|
+
const startLng = start?.longitude ?? 0;
|
|
84
83
|
const endLat = end.latitude;
|
|
85
84
|
const endLng = end.longitude;
|
|
86
85
|
return nativeRef.current.startNavigation(startLat, startLng, endLat, endLng);
|
|
@@ -28,9 +28,8 @@ const ExpoGaodeMapModuleWithHelpers = {
|
|
|
28
28
|
* 初始化 SDK,并缓存配置(包含 webKey)
|
|
29
29
|
*/
|
|
30
30
|
initSDK(config) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
(_a = nativeModule === null || nativeModule === void 0 ? void 0 : nativeModule.initSDK) === null || _a === void 0 ? void 0 : _a.call(nativeModule, config);
|
|
31
|
+
_sdkConfig = config ?? null;
|
|
32
|
+
nativeModule?.initSDK?.(config);
|
|
34
33
|
},
|
|
35
34
|
/**
|
|
36
35
|
* 添加定位监听器(便捷方法)
|
|
@@ -40,9 +39,8 @@ const ExpoGaodeMapModuleWithHelpers = {
|
|
|
40
39
|
* @throws 如果底层模块不可用,返回一个空操作的订阅对象
|
|
41
40
|
*/
|
|
42
41
|
addLocationListener(listener) {
|
|
43
|
-
var _a;
|
|
44
42
|
// 使用可选链和空值合并,确保即使模块不可用也不会崩溃
|
|
45
|
-
return
|
|
43
|
+
return nativeModule?.addListener?.('onLocationUpdate', listener) || {
|
|
46
44
|
remove: () => { },
|
|
47
45
|
};
|
|
48
46
|
},
|
|
@@ -57,6 +55,6 @@ function getSDKConfig() {
|
|
|
57
55
|
* 获取用于 Web API 的 webKey(若未初始化或未提供则返回 undefined)
|
|
58
56
|
*/
|
|
59
57
|
function getWebKey() {
|
|
60
|
-
return _sdkConfig
|
|
58
|
+
return _sdkConfig?.webKey;
|
|
61
59
|
}
|
|
62
60
|
exports.default = ExpoGaodeMapModuleWithHelpers;
|
|
@@ -17,7 +17,7 @@ class EventManager {
|
|
|
17
17
|
}
|
|
18
18
|
trigger(id, eventType, data) {
|
|
19
19
|
const callbacks = this.callbacks.get(id);
|
|
20
|
-
const callback = callbacks
|
|
20
|
+
const callback = callbacks?.[eventType];
|
|
21
21
|
if (typeof callback === 'function') {
|
|
22
22
|
callback(data);
|
|
23
23
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import AMapLocationKit
|
|
3
3
|
import CoreLocation
|
|
4
|
+
import ExpoModulesCore
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* 定位管理器
|
|
@@ -123,6 +124,13 @@ class LocationManager: NSObject, AMapLocationManagerDelegate {
|
|
|
123
124
|
* @param allows 是否允许后台定位
|
|
124
125
|
*/
|
|
125
126
|
func setAllowsBackgroundLocationUpdates(_ allows: Bool) {
|
|
127
|
+
if allows {
|
|
128
|
+
let backgroundModes = Bundle.main.object(forInfoDictionaryKey: "UIBackgroundModes") as? [String]
|
|
129
|
+
if backgroundModes?.contains("location") != true {
|
|
130
|
+
log.warn("⚠️ [ExpoGaodeMap] iOS 后台定位未正确配置,setAllowsBackgroundLocationUpdates(true) 可能不会生效,请检查 Info.plist 是否包含 UIBackgroundModes: location,或者在 app.json 中配置 enableBackgroundLocation: true,然后重新执行 npx expo prebuild")
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
}
|
|
126
134
|
locationManager?.allowsBackgroundLocationUpdates = allows
|
|
127
135
|
}
|
|
128
136
|
|
|
@@ -262,4 +270,4 @@ class LocationManager: NSObject, AMapLocationManagerDelegate {
|
|
|
262
270
|
func amapLocationManager(_ manager: AMapLocationManager!, didFailWithError error: Error!) {
|
|
263
271
|
// 定位失败 - 静默处理
|
|
264
272
|
}
|
|
265
|
-
}
|
|
273
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-gaode-map-navigation",
|
|
3
|
-
"version": "1.1.5-next.
|
|
3
|
+
"version": "1.1.5-next.1",
|
|
4
4
|
"description": "高德地图导航功能模块 - 路径规划、导航引导,独立版本包含完整地图功能",
|
|
5
5
|
"author": "<TomWq> (https://github.com/TomWq)",
|
|
6
6
|
"repository": "https://github.com/TomWq/expo-gaode-map",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"lint": "expo-module lint",
|
|
14
14
|
"test": "expo-module test",
|
|
15
15
|
"prepare": "expo-module prepare && bun run build:plugin",
|
|
16
|
-
"prepublishOnly": "
|
|
16
|
+
"prepublishOnly": "echo 'Skipping proofread check' && exit 0",
|
|
17
17
|
"expo-module": "expo-module"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|