expo-gaode-map 1.1.8 → 2.0.0-alpha.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.en.md +32 -46
- package/README.md +50 -70
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapView.kt +37 -268
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapViewModule.kt +1 -49
- package/android/src/main/java/expo/modules/gaodemap/managers/CameraManager.kt +30 -7
- package/android/src/main/java/expo/modules/gaodemap/managers/UIManager.kt +1 -0
- package/android/src/main/java/expo/modules/gaodemap/modules/LocationManager.kt +10 -1
- package/android/src/main/java/expo/modules/gaodemap/overlays/CircleView.kt +38 -14
- package/android/src/main/java/expo/modules/gaodemap/overlays/CircleViewModule.kt +3 -3
- package/android/src/main/java/expo/modules/gaodemap/overlays/ClusterView.kt +8 -1
- package/android/src/main/java/expo/modules/gaodemap/overlays/HeatMapView.kt +4 -1
- package/android/src/main/java/expo/modules/gaodemap/overlays/MarkerView.kt +322 -93
- package/android/src/main/java/expo/modules/gaodemap/overlays/MarkerViewModule.kt +11 -3
- package/android/src/main/java/expo/modules/gaodemap/overlays/MultiPointView.kt +4 -1
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolygonView.kt +25 -11
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolygonViewModule.kt +3 -3
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolylineView.kt +20 -10
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolylineViewModule.kt +6 -2
- package/build/ExpoGaodeMap.types.d.ts +27 -6
- package/build/ExpoGaodeMap.types.d.ts.map +1 -1
- package/build/ExpoGaodeMap.types.js +3 -0
- package/build/ExpoGaodeMap.types.js.map +1 -1
- package/build/ExpoGaodeMapModule.d.ts +157 -10
- package/build/ExpoGaodeMapModule.d.ts.map +1 -1
- package/build/ExpoGaodeMapModule.js +4 -0
- package/build/ExpoGaodeMapModule.js.map +1 -1
- package/build/ExpoGaodeMapView.d.ts +1 -17
- package/build/ExpoGaodeMapView.d.ts.map +1 -1
- package/build/ExpoGaodeMapView.js +4 -221
- package/build/ExpoGaodeMapView.js.map +1 -1
- package/build/components/overlays/Circle.d.ts +11 -1
- package/build/components/overlays/Circle.d.ts.map +1 -1
- package/build/components/overlays/Circle.js +12 -58
- package/build/components/overlays/Circle.js.map +1 -1
- package/build/components/overlays/Cluster.d.ts.map +1 -1
- package/build/components/overlays/Cluster.js.map +1 -1
- package/build/components/overlays/Marker.d.ts +13 -1
- package/build/components/overlays/Marker.d.ts.map +1 -1
- package/build/components/overlays/Marker.js +51 -115
- package/build/components/overlays/Marker.js.map +1 -1
- package/build/components/overlays/Polygon.d.ts +7 -15
- package/build/components/overlays/Polygon.d.ts.map +1 -1
- package/build/components/overlays/Polygon.js +10 -80
- package/build/components/overlays/Polygon.js.map +1 -1
- package/build/components/overlays/Polyline.d.ts +7 -14
- package/build/components/overlays/Polyline.d.ts.map +1 -1
- package/build/components/overlays/Polyline.js +9 -66
- package/build/components/overlays/Polyline.js.map +1 -1
- package/build/index.d.ts +1 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -10
- package/build/index.js.map +1 -1
- package/build/types/map-view.types.d.ts +0 -90
- package/build/types/map-view.types.d.ts.map +1 -1
- package/build/types/map-view.types.js.map +1 -1
- package/build/types/overlays.types.d.ts +9 -9
- package/build/types/overlays.types.d.ts.map +1 -1
- package/build/types/overlays.types.js.map +1 -1
- package/docs/API.en.md +1 -21
- package/docs/API.md +84 -56
- package/docs/EXAMPLES.en.md +0 -48
- package/docs/EXAMPLES.md +49 -102
- package/docs/INITIALIZATION.md +59 -71
- package/docs/MIGRATION.md +423 -0
- package/ios/ExpoGaodeMapView.swift +317 -258
- package/ios/ExpoGaodeMapViewModule.swift +3 -50
- package/ios/managers/CameraManager.swift +23 -2
- package/ios/managers/UIManager.swift +10 -5
- package/ios/modules/LocationManager.swift +10 -0
- package/ios/overlays/CircleView.swift +98 -19
- package/ios/overlays/CircleViewModule.swift +21 -0
- package/ios/overlays/ClusterView.swift +33 -4
- package/ios/overlays/HeatMapView.swift +16 -4
- package/ios/overlays/MarkerView.swift +235 -146
- package/ios/overlays/MarkerViewModule.swift +7 -3
- package/ios/overlays/MultiPointView.swift +30 -1
- package/ios/overlays/PolygonView.swift +63 -12
- package/ios/overlays/PolygonViewModule.swift +17 -0
- package/ios/overlays/PolylineView.swift +95 -25
- package/ios/overlays/PolylineViewModule.swift +17 -8
- package/ios/utils/PermissionManager.swift +9 -14
- package/package.json +4 -3
- package/src/ExpoGaodeMap.types.ts +28 -3
- package/src/ExpoGaodeMapModule.ts +201 -12
- package/src/ExpoGaodeMapView.tsx +9 -234
- package/src/components/overlays/Circle.tsx +14 -70
- package/src/components/overlays/Cluster.tsx +0 -1
- package/src/components/overlays/Marker.tsx +63 -138
- package/src/components/overlays/Polygon.tsx +12 -92
- package/src/components/overlays/Polyline.tsx +11 -77
- package/src/index.ts +4 -29
- package/src/types/map-view.types.ts +1 -85
- package/src/types/overlays.types.ts +9 -9
- package/android/src/main/java/expo/modules/gaodemap/managers/OverlayManager.kt +0 -574
- package/build/modules/AMapLocation.d.ts +0 -78
- package/build/modules/AMapLocation.d.ts.map +0 -1
- package/build/modules/AMapLocation.js +0 -132
- package/build/modules/AMapLocation.js.map +0 -1
- package/build/modules/AMapPermissions.d.ts +0 -29
- package/build/modules/AMapPermissions.d.ts.map +0 -1
- package/build/modules/AMapPermissions.js +0 -23
- package/build/modules/AMapPermissions.js.map +0 -1
- package/build/modules/AMapSDK.d.ts +0 -22
- package/build/modules/AMapSDK.d.ts.map +0 -1
- package/build/modules/AMapSDK.js +0 -25
- package/build/modules/AMapSDK.js.map +0 -1
- package/build/modules/AMapView.d.ts +0 -44
- package/build/modules/AMapView.d.ts.map +0 -1
- package/build/modules/AMapView.js +0 -65
- package/build/modules/AMapView.js.map +0 -1
- package/ios/managers/OverlayManager.swift +0 -522
- package/src/modules/AMapLocation.ts +0 -165
- package/src/modules/AMapPermissions.ts +0 -41
- package/src/modules/AMapSDK.ts +0 -31
- package/src/modules/AMapView.ts +0 -72
package/docs/EXAMPLES.md
CHANGED
|
@@ -23,10 +23,7 @@ import { useEffect, useState } from 'react';
|
|
|
23
23
|
import { View, Text, Alert, Linking, Platform } from 'react-native';
|
|
24
24
|
import {
|
|
25
25
|
MapView,
|
|
26
|
-
|
|
27
|
-
checkLocationPermission,
|
|
28
|
-
requestLocationPermission,
|
|
29
|
-
getCurrentLocation,
|
|
26
|
+
ExpoGaodeMapModule,
|
|
30
27
|
type LatLng,
|
|
31
28
|
} from 'expo-gaode-map';
|
|
32
29
|
|
|
@@ -41,17 +38,17 @@ export default function App() {
|
|
|
41
38
|
const initialize = async () => {
|
|
42
39
|
try {
|
|
43
40
|
// 1. 初始化 SDK
|
|
44
|
-
initSDK({
|
|
41
|
+
ExpoGaodeMapModule.initSDK({
|
|
45
42
|
androidKey: 'your-android-api-key',
|
|
46
43
|
iosKey: 'your-ios-api-key',
|
|
47
44
|
});
|
|
48
45
|
|
|
49
46
|
// 2. 检查权限
|
|
50
|
-
const status = await checkLocationPermission();
|
|
47
|
+
const status = await ExpoGaodeMapModule.checkLocationPermission();
|
|
51
48
|
|
|
52
49
|
// 3. 请求权限(如果需要)
|
|
53
50
|
if (!status.granted) {
|
|
54
|
-
const result = await requestLocationPermission();
|
|
51
|
+
const result = await ExpoGaodeMapModule.requestLocationPermission();
|
|
55
52
|
|
|
56
53
|
if (!result.granted) {
|
|
57
54
|
// 权限被拒绝
|
|
@@ -61,28 +58,26 @@ export default function App() {
|
|
|
61
58
|
});
|
|
62
59
|
|
|
63
60
|
// 引导用户到设置
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
);
|
|
79
|
-
}
|
|
61
|
+
Alert.alert(
|
|
62
|
+
'需要定位权限',
|
|
63
|
+
'请在设置中开启定位权限',
|
|
64
|
+
[
|
|
65
|
+
{ text: '取消' },
|
|
66
|
+
{ text: '去设置', onPress: () => {
|
|
67
|
+
if (Platform.OS === 'ios') {
|
|
68
|
+
Linking.openURL('app-settings:');
|
|
69
|
+
} else {
|
|
70
|
+
Linking.openSettings();
|
|
71
|
+
}
|
|
72
|
+
}}
|
|
73
|
+
]
|
|
74
|
+
);
|
|
80
75
|
return;
|
|
81
76
|
}
|
|
82
77
|
}
|
|
83
78
|
|
|
84
79
|
// 4. 获取位置
|
|
85
|
-
const location = await getCurrentLocation();
|
|
80
|
+
const location = await ExpoGaodeMapModule.getCurrentLocation();
|
|
86
81
|
setInitialPosition({
|
|
87
82
|
target: {
|
|
88
83
|
latitude: location.latitude,
|
|
@@ -138,14 +133,14 @@ export default function App() {
|
|
|
138
133
|
```tsx
|
|
139
134
|
import React, { useRef, useEffect } from 'react';
|
|
140
135
|
import { View, StyleSheet, Button } from 'react-native';
|
|
141
|
-
import {
|
|
142
|
-
MapView,
|
|
143
|
-
|
|
136
|
+
import {
|
|
137
|
+
MapView,
|
|
138
|
+
ExpoGaodeMapModule,
|
|
144
139
|
Circle,
|
|
145
140
|
Marker,
|
|
146
141
|
Polyline,
|
|
147
142
|
Polygon,
|
|
148
|
-
type MapViewRef
|
|
143
|
+
type MapViewRef
|
|
149
144
|
} from 'expo-gaode-map';
|
|
150
145
|
|
|
151
146
|
export default function App() {
|
|
@@ -153,15 +148,15 @@ export default function App() {
|
|
|
153
148
|
|
|
154
149
|
useEffect(() => {
|
|
155
150
|
const initialize = async () => {
|
|
156
|
-
initSDK({
|
|
151
|
+
ExpoGaodeMapModule.initSDK({
|
|
157
152
|
androidKey: 'your-android-api-key',
|
|
158
153
|
iosKey: 'your-ios-api-key',
|
|
159
154
|
});
|
|
160
155
|
|
|
161
156
|
// 检查并请求权限
|
|
162
|
-
const status = await checkLocationPermission();
|
|
157
|
+
const status = await ExpoGaodeMapModule.checkLocationPermission();
|
|
163
158
|
if (!status.granted) {
|
|
164
|
-
await requestLocationPermission();
|
|
159
|
+
await ExpoGaodeMapModule.requestLocationPermission();
|
|
165
160
|
}
|
|
166
161
|
};
|
|
167
162
|
|
|
@@ -261,14 +256,9 @@ const styles = StyleSheet.create({
|
|
|
261
256
|
```tsx
|
|
262
257
|
import React, { useEffect, useState } from 'react';
|
|
263
258
|
import { View, Text, Button, StyleSheet } from 'react-native';
|
|
264
|
-
import {
|
|
259
|
+
import {
|
|
265
260
|
MapView,
|
|
266
|
-
|
|
267
|
-
configure,
|
|
268
|
-
start,
|
|
269
|
-
stop,
|
|
270
|
-
getCurrentLocation,
|
|
271
|
-
addLocationListener,
|
|
261
|
+
ExpoGaodeMapModule,
|
|
272
262
|
type Location,
|
|
273
263
|
} from 'expo-gaode-map';
|
|
274
264
|
|
|
@@ -279,26 +269,24 @@ export default function LocationApp() {
|
|
|
279
269
|
useEffect(() => {
|
|
280
270
|
const initialize = async () => {
|
|
281
271
|
// 初始化 SDK
|
|
282
|
-
initSDK({
|
|
272
|
+
ExpoGaodeMapModule.initSDK({
|
|
283
273
|
androidKey: 'your-android-api-key',
|
|
284
274
|
iosKey: 'your-ios-api-key',
|
|
285
275
|
});
|
|
286
276
|
|
|
287
277
|
// 检查并请求权限
|
|
288
|
-
const status = await checkLocationPermission();
|
|
278
|
+
const status = await ExpoGaodeMapModule.checkLocationPermission();
|
|
289
279
|
if (!status.granted) {
|
|
290
|
-
await requestLocationPermission();
|
|
280
|
+
await ExpoGaodeMapModule.requestLocationPermission();
|
|
291
281
|
}
|
|
292
282
|
|
|
293
283
|
// 配置定位参数
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
interval: 2000,
|
|
298
|
-
});
|
|
284
|
+
ExpoGaodeMapModule.setLocatingWithReGeocode(true);
|
|
285
|
+
ExpoGaodeMapModule.setLocationMode(0);
|
|
286
|
+
ExpoGaodeMapModule.setInterval(2000);
|
|
299
287
|
|
|
300
288
|
// 监听位置更新
|
|
301
|
-
const subscription =
|
|
289
|
+
const subscription = ExpoGaodeMapModule.addListener('onLocationUpdate', (loc) => {
|
|
302
290
|
console.log('位置更新:', loc);
|
|
303
291
|
setLocation(loc);
|
|
304
292
|
});
|
|
@@ -310,18 +298,18 @@ export default function LocationApp() {
|
|
|
310
298
|
}, []);
|
|
311
299
|
|
|
312
300
|
const handleStartTracking = () => {
|
|
313
|
-
start();
|
|
301
|
+
ExpoGaodeMapModule.start();
|
|
314
302
|
setIsTracking(true);
|
|
315
303
|
};
|
|
316
304
|
|
|
317
305
|
const handleStopTracking = () => {
|
|
318
|
-
stop();
|
|
306
|
+
ExpoGaodeMapModule.stop();
|
|
319
307
|
setIsTracking(false);
|
|
320
308
|
};
|
|
321
309
|
|
|
322
310
|
const handleGetLocation = async () => {
|
|
323
311
|
try {
|
|
324
|
-
const loc = await getCurrentLocation();
|
|
312
|
+
const loc = await ExpoGaodeMapModule.getCurrentLocation();
|
|
325
313
|
setLocation(loc);
|
|
326
314
|
} catch (error) {
|
|
327
315
|
console.error('获取位置失败:', error);
|
|
@@ -431,24 +419,6 @@ const styles = StyleSheet.create({
|
|
|
431
419
|
</MapView>
|
|
432
420
|
```
|
|
433
421
|
|
|
434
|
-
**命令式用法:**
|
|
435
|
-
```tsx
|
|
436
|
-
const mapRef = useRef<MapViewRef>(null);
|
|
437
|
-
|
|
438
|
-
await mapRef.current?.addCircle('circle1', {
|
|
439
|
-
center: { latitude: 39.9, longitude: 116.4 },
|
|
440
|
-
radius: 1000,
|
|
441
|
-
fillColor: 0x8800FF00,
|
|
442
|
-
strokeColor: 0xFFFF0000,
|
|
443
|
-
strokeWidth: 2,
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
await mapRef.current?.updateCircle('circle1', {
|
|
447
|
-
radius: 2000,
|
|
448
|
-
});
|
|
449
|
-
|
|
450
|
-
await mapRef.current?.removeCircle('circle1');
|
|
451
|
-
```
|
|
452
422
|
|
|
453
423
|
### Marker (标记点)
|
|
454
424
|
|
|
@@ -919,37 +889,6 @@ const iconUri = Image.resolveAssetSource(require('./assets/location-icon.png')).
|
|
|
919
889
|
/>
|
|
920
890
|
```
|
|
921
891
|
|
|
922
|
-
### 批量操作覆盖物
|
|
923
|
-
|
|
924
|
-
```tsx
|
|
925
|
-
const mapRef = useRef<MapViewRef>(null);
|
|
926
|
-
|
|
927
|
-
const addMultipleOverlays = async () => {
|
|
928
|
-
await mapRef.current?.addCircle('circle1', {
|
|
929
|
-
center: { latitude: 39.9, longitude: 116.4 },
|
|
930
|
-
radius: 1000,
|
|
931
|
-
fillColor: 0x8800FF00,
|
|
932
|
-
});
|
|
933
|
-
|
|
934
|
-
await mapRef.current?.addCircle('circle2', {
|
|
935
|
-
center: { latitude: 40.0, longitude: 116.5 },
|
|
936
|
-
radius: 500,
|
|
937
|
-
fillColor: 0x880000FF,
|
|
938
|
-
});
|
|
939
|
-
|
|
940
|
-
await mapRef.current?.addMarker('marker1', {
|
|
941
|
-
position: { latitude: 39.95, longitude: 116.45 },
|
|
942
|
-
title: '北京',
|
|
943
|
-
});
|
|
944
|
-
};
|
|
945
|
-
|
|
946
|
-
const clearAll = async () => {
|
|
947
|
-
await mapRef.current?.removeCircle('circle1');
|
|
948
|
-
await mapRef.current?.removeCircle('circle2');
|
|
949
|
-
await mapRef.current?.removeMarker('marker1');
|
|
950
|
-
};
|
|
951
|
-
```
|
|
952
|
-
|
|
953
892
|
### 缩放级别限制
|
|
954
893
|
|
|
955
894
|
```tsx
|
|
@@ -966,10 +905,18 @@ const clearAll = async () => {
|
|
|
966
905
|
### 方向更新 (iOS)
|
|
967
906
|
|
|
968
907
|
```tsx
|
|
969
|
-
import {
|
|
908
|
+
import { ExpoGaodeMapModule } from 'expo-gaode-map';
|
|
970
909
|
|
|
971
910
|
// 开始方向更新
|
|
972
|
-
startUpdatingHeading();
|
|
911
|
+
ExpoGaodeMapModule.startUpdatingHeading();
|
|
973
912
|
|
|
974
913
|
// 停止方向更新
|
|
975
|
-
stopUpdatingHeading();
|
|
914
|
+
ExpoGaodeMapModule.stopUpdatingHeading();
|
|
915
|
+
|
|
916
|
+
// 监听方向更新
|
|
917
|
+
const subscription = ExpoGaodeMapModule.addListener('onHeadingUpdate', (heading) => {
|
|
918
|
+
console.log('方向更新:', heading);
|
|
919
|
+
});
|
|
920
|
+
|
|
921
|
+
// 取消监听
|
|
922
|
+
subscription.remove();
|
package/docs/INITIALIZATION.md
CHANGED
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
在应用启动时初始化 SDK(通常在 App 组件的 useEffect 中):
|
|
19
19
|
|
|
20
20
|
```tsx
|
|
21
|
-
import {
|
|
21
|
+
import { ExpoGaodeMapModule } from 'expo-gaode-map';
|
|
22
22
|
|
|
23
23
|
useEffect(() => {
|
|
24
|
-
initSDK({
|
|
24
|
+
ExpoGaodeMapModule.initSDK({
|
|
25
25
|
androidKey: 'your-android-api-key',
|
|
26
26
|
iosKey: 'your-ios-api-key',
|
|
27
27
|
});
|
|
@@ -33,19 +33,16 @@ useEffect(() => {
|
|
|
33
33
|
在使用定位功能前,必须先检查和请求权限:
|
|
34
34
|
|
|
35
35
|
```tsx
|
|
36
|
-
import {
|
|
37
|
-
checkLocationPermission,
|
|
38
|
-
requestLocationPermission
|
|
39
|
-
} from 'expo-gaode-map';
|
|
36
|
+
import { ExpoGaodeMapModule } from 'expo-gaode-map';
|
|
40
37
|
|
|
41
38
|
// 检查权限状态
|
|
42
|
-
const status = await checkLocationPermission();
|
|
39
|
+
const status = await ExpoGaodeMapModule.checkLocationPermission();
|
|
43
40
|
console.log('权限状态:', status);
|
|
44
|
-
// { granted: boolean,
|
|
41
|
+
// { granted: boolean, status: string }
|
|
45
42
|
|
|
46
43
|
// 请求权限
|
|
47
44
|
if (!status.granted) {
|
|
48
|
-
const result = await requestLocationPermission();
|
|
45
|
+
const result = await ExpoGaodeMapModule.requestLocationPermission();
|
|
49
46
|
if (result.granted) {
|
|
50
47
|
console.log('权限已授予');
|
|
51
48
|
} else {
|
|
@@ -59,10 +56,10 @@ if (!status.granted) {
|
|
|
59
56
|
权限授予后,可以获取当前位置:
|
|
60
57
|
|
|
61
58
|
```tsx
|
|
62
|
-
import {
|
|
59
|
+
import { ExpoGaodeMapModule } from 'expo-gaode-map';
|
|
63
60
|
|
|
64
61
|
try {
|
|
65
|
-
const location = await getCurrentLocation();
|
|
62
|
+
const location = await ExpoGaodeMapModule.getCurrentLocation();
|
|
66
63
|
console.log('当前位置:', location);
|
|
67
64
|
} catch (error) {
|
|
68
65
|
console.error('获取位置失败:', error);
|
|
@@ -75,23 +72,23 @@ try {
|
|
|
75
72
|
|
|
76
73
|
| API | 说明 | 返回值 |
|
|
77
74
|
|-----|------|--------|
|
|
78
|
-
| `checkLocationPermission()` | 检查定位权限状态 | `Promise<PermissionStatus>` |
|
|
79
|
-
| `requestLocationPermission()` | 请求定位权限 | `Promise<PermissionStatus>` |
|
|
75
|
+
| `ExpoGaodeMapModule.checkLocationPermission()` | 检查定位权限状态 | `Promise<PermissionStatus>` |
|
|
76
|
+
| `ExpoGaodeMapModule.requestLocationPermission()` | 请求定位权限 | `Promise<PermissionStatus>` |
|
|
80
77
|
|
|
81
78
|
### PermissionStatus 类型
|
|
82
79
|
|
|
83
80
|
```typescript
|
|
84
81
|
interface PermissionStatus {
|
|
85
|
-
granted: boolean;
|
|
86
|
-
|
|
82
|
+
granted: boolean; // 是否已授予权限
|
|
83
|
+
status: string; // 权限状态字符串
|
|
87
84
|
}
|
|
88
85
|
```
|
|
89
86
|
|
|
90
87
|
### 权限状态说明
|
|
91
88
|
|
|
92
89
|
- **granted: true** - 用户已授予权限,可以使用定位功能
|
|
93
|
-
- **granted: false
|
|
94
|
-
- **
|
|
90
|
+
- **granted: false** - 用户未授予权限
|
|
91
|
+
- **status** - 权限状态字符串(notDetermined, denied, authorizedWhenInUse, authorizedAlways 等)
|
|
95
92
|
|
|
96
93
|
## 完整示例
|
|
97
94
|
|
|
@@ -99,13 +96,10 @@ interface PermissionStatus {
|
|
|
99
96
|
|
|
100
97
|
```tsx
|
|
101
98
|
import { useEffect, useState } from 'react';
|
|
102
|
-
import { Alert, Platform } from 'react-native';
|
|
103
|
-
import {
|
|
99
|
+
import { Alert, Platform, Linking } from 'react-native';
|
|
100
|
+
import {
|
|
104
101
|
MapView,
|
|
105
|
-
|
|
106
|
-
checkLocationPermission,
|
|
107
|
-
requestLocationPermission,
|
|
108
|
-
getCurrentLocation,
|
|
102
|
+
ExpoGaodeMapModule,
|
|
109
103
|
type LatLng,
|
|
110
104
|
} from 'expo-gaode-map';
|
|
111
105
|
|
|
@@ -120,17 +114,17 @@ export default function App() {
|
|
|
120
114
|
try {
|
|
121
115
|
// 1. 初始化 SDK
|
|
122
116
|
console.log('正在初始化高德地图 SDK...');
|
|
123
|
-
initSDK({
|
|
117
|
+
ExpoGaodeMapModule.initSDK({
|
|
124
118
|
androidKey: 'your-android-api-key',
|
|
125
119
|
iosKey: 'your-ios-api-key',
|
|
126
120
|
});
|
|
127
121
|
|
|
128
122
|
// 2. 检查权限
|
|
129
|
-
const status = await checkLocationPermission();
|
|
123
|
+
const status = await ExpoGaodeMapModule.checkLocationPermission();
|
|
130
124
|
|
|
131
125
|
// 3. 如果没有权限,请求权限
|
|
132
126
|
if (!status.granted) {
|
|
133
|
-
const result = await requestLocationPermission();
|
|
127
|
+
const result = await ExpoGaodeMapModule.requestLocationPermission();
|
|
134
128
|
|
|
135
129
|
if (!result.granted) {
|
|
136
130
|
// 权限被拒绝,使用默认位置
|
|
@@ -140,30 +134,28 @@ export default function App() {
|
|
|
140
134
|
zoom: 10
|
|
141
135
|
});
|
|
142
136
|
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
);
|
|
160
|
-
}
|
|
137
|
+
// 引导用户到设置
|
|
138
|
+
Alert.alert(
|
|
139
|
+
'需要定位权限',
|
|
140
|
+
'请在设置中开启定位权限以使用完整功能',
|
|
141
|
+
[
|
|
142
|
+
{ text: '取消', style: 'cancel' },
|
|
143
|
+
{ text: '去设置', onPress: () => {
|
|
144
|
+
// 打开应用设置
|
|
145
|
+
if (Platform.OS === 'ios') {
|
|
146
|
+
Linking.openURL('app-settings:');
|
|
147
|
+
} else {
|
|
148
|
+
Linking.openSettings();
|
|
149
|
+
}
|
|
150
|
+
}}
|
|
151
|
+
]
|
|
152
|
+
);
|
|
161
153
|
return;
|
|
162
154
|
}
|
|
163
155
|
}
|
|
164
156
|
|
|
165
157
|
// 4. 获取当前位置
|
|
166
|
-
const location = await getCurrentLocation();
|
|
158
|
+
const location = await ExpoGaodeMapModule.getCurrentLocation();
|
|
167
159
|
console.log('当前位置:', location);
|
|
168
160
|
|
|
169
161
|
// 5. 设置地图初始位置
|
|
@@ -208,7 +200,7 @@ export default function App() {
|
|
|
208
200
|
|
|
209
201
|
1. **初始化顺序**:
|
|
210
202
|
```
|
|
211
|
-
initSDK →
|
|
203
|
+
ExpoGaodeMapModule.initSDK → checkLocationPermission → requestLocationPermission → getCurrentLocation → 渲染地图
|
|
212
204
|
```
|
|
213
205
|
|
|
214
206
|
2. **权限处理**:
|
|
@@ -237,17 +229,15 @@ if (!result.granted) {
|
|
|
237
229
|
zoom: 10
|
|
238
230
|
});
|
|
239
231
|
|
|
240
|
-
//
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
);
|
|
250
|
-
}
|
|
232
|
+
// 引导到设置
|
|
233
|
+
Alert.alert(
|
|
234
|
+
'需要定位权限',
|
|
235
|
+
'请在设置中开启定位权限',
|
|
236
|
+
[
|
|
237
|
+
{ text: '取消' },
|
|
238
|
+
{ text: '去设置', onPress: () => Linking.openSettings() }
|
|
239
|
+
]
|
|
240
|
+
);
|
|
251
241
|
}
|
|
252
242
|
```
|
|
253
243
|
|
|
@@ -267,26 +257,24 @@ await mapRef.current?.moveCamera({
|
|
|
267
257
|
|
|
268
258
|
### Q: 如何配置定位参数?
|
|
269
259
|
|
|
270
|
-
**A:**
|
|
260
|
+
**A:** 使用配置方法,**必须在 `initSDK` 之后调用**:
|
|
271
261
|
|
|
272
262
|
```tsx
|
|
273
|
-
import {
|
|
263
|
+
import { ExpoGaodeMapModule } from 'expo-gaode-map';
|
|
274
264
|
|
|
275
265
|
// 1. 先初始化 SDK
|
|
276
|
-
initSDK({
|
|
266
|
+
ExpoGaodeMapModule.initSDK({
|
|
277
267
|
androidKey: 'your-android-api-key',
|
|
278
268
|
iosKey: 'your-ios-api-key',
|
|
279
269
|
});
|
|
280
270
|
|
|
281
271
|
// 2. 再配置定位参数
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
interval: 2000, // 2秒更新一次
|
|
286
|
-
});
|
|
272
|
+
ExpoGaodeMapModule.setLocatingWithReGeocode(true); // 返回地址信息
|
|
273
|
+
ExpoGaodeMapModule.setLocationMode(0); // 高精度模式
|
|
274
|
+
ExpoGaodeMapModule.setInterval(2000); // 2秒更新一次
|
|
287
275
|
```
|
|
288
276
|
|
|
289
|
-
> ⚠️ **重要**:
|
|
277
|
+
> ⚠️ **重要**: 配置方法必须在 `initSDK` 之后调用,否则配置可能不生效。
|
|
290
278
|
|
|
291
279
|
### Q: Android 和 iOS 的初始化有区别吗?
|
|
292
280
|
|
|
@@ -307,13 +295,13 @@ configure({
|
|
|
307
295
|
1. **总是处理权限**:
|
|
308
296
|
```tsx
|
|
309
297
|
// ✅ 好的做法
|
|
310
|
-
const status = await checkLocationPermission();
|
|
298
|
+
const status = await ExpoGaodeMapModule.checkLocationPermission();
|
|
311
299
|
if (!status.granted) {
|
|
312
|
-
await requestLocationPermission();
|
|
300
|
+
await ExpoGaodeMapModule.requestLocationPermission();
|
|
313
301
|
}
|
|
314
302
|
|
|
315
303
|
// ❌ 不好的做法
|
|
316
|
-
await getCurrentLocation(); // 可能因为没有权限而失败
|
|
304
|
+
await ExpoGaodeMapModule.getCurrentLocation(); // 可能因为没有权限而失败
|
|
317
305
|
```
|
|
318
306
|
|
|
319
307
|
2. **提供加载状态**:
|
|
@@ -326,7 +314,7 @@ configure({
|
|
|
326
314
|
3. **错误处理**:
|
|
327
315
|
```tsx
|
|
328
316
|
try {
|
|
329
|
-
const location = await getCurrentLocation();
|
|
317
|
+
const location = await ExpoGaodeMapModule.getCurrentLocation();
|
|
330
318
|
} catch (error) {
|
|
331
319
|
console.error('获取位置失败:', error);
|
|
332
320
|
// 使用默认位置
|
|
@@ -336,7 +324,7 @@ configure({
|
|
|
336
324
|
4. **避免重复初始化**:
|
|
337
325
|
```tsx
|
|
338
326
|
useEffect(() => {
|
|
339
|
-
initSDK({ ... });
|
|
327
|
+
ExpoGaodeMapModule.initSDK({ ... });
|
|
340
328
|
}, []); // 空依赖数组,只初始化一次
|
|
341
329
|
```
|
|
342
330
|
|