expo-gaode-map 1.0.6 → 1.0.7
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 +320 -0
- package/README.md +2 -0
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapModule.kt +1 -298
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapViewModule.kt +126 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/CircleViewModule.kt +41 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/ClusterViewModule.kt +29 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/HeatMapViewModule.kt +27 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/MarkerViewModule.kt +49 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/MultiPointViewModule.kt +21 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolygonViewModule.kt +37 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolylineView.kt +2 -0
- package/android/src/main/java/expo/modules/gaodemap/overlays/PolylineViewModule.kt +45 -0
- package/build/ExpoGaodeMapView.js +1 -1
- package/build/ExpoGaodeMapView.js.map +1 -1
- package/build/components/overlays/Cluster.d.ts.map +1 -1
- package/build/components/overlays/Cluster.js +1 -1
- package/build/components/overlays/Cluster.js.map +1 -1
- package/build/components/overlays/HeatMap.d.ts.map +1 -1
- package/build/components/overlays/HeatMap.js +1 -1
- package/build/components/overlays/HeatMap.js.map +1 -1
- package/build/components/overlays/MultiPoint.d.ts.map +1 -1
- package/build/components/overlays/MultiPoint.js +1 -1
- package/build/components/overlays/MultiPoint.js.map +1 -1
- package/docs/API.en.md +418 -0
- package/docs/API.md +2 -0
- package/docs/ARCHITECTURE.en.md +423 -0
- package/docs/ARCHITECTURE.md +2 -0
- package/docs/EXAMPLES.en.md +642 -0
- package/docs/EXAMPLES.md +2 -0
- package/docs/INITIALIZATION.en.md +346 -0
- package/docs/INITIALIZATION.md +2 -0
- package/expo-module.config.json +22 -2
- package/ios/ExpoGaodeMapModule.swift +0 -334
- package/ios/ExpoGaodeMapViewModule.swift +155 -0
- package/ios/overlays/CircleViewModule.swift +31 -0
- package/ios/overlays/ClusterViewModule.swift +23 -0
- package/ios/overlays/HeatMapViewModule.swift +21 -0
- package/ios/overlays/MarkerViewModule.swift +55 -0
- package/ios/overlays/MultiPointViewModule.swift +15 -0
- package/ios/overlays/PolygonViewModule.swift +27 -0
- package/ios/overlays/PolylineViewModule.swift +39 -0
- package/package.json +1 -1
- package/src/ExpoGaodeMapView.tsx +1 -1
- package/src/components/overlays/Cluster.tsx +2 -1
- package/src/components/overlays/HeatMap.tsx +2 -1
- package/src/components/overlays/MultiPoint.tsx +2 -1
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
# Initialization Guide
|
|
2
|
+
|
|
3
|
+
English | [简体中文](./INITIALIZATION.md)
|
|
4
|
+
|
|
5
|
+
This document explains how to properly initialize and configure expo-gaode-map.
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Basic Initialization Process](#basic-initialization-process)
|
|
10
|
+
- [Permission Management](#permission-management)
|
|
11
|
+
- [Complete Example](#complete-example)
|
|
12
|
+
- [Common Issues](#common-issues)
|
|
13
|
+
|
|
14
|
+
## Basic Initialization Process
|
|
15
|
+
|
|
16
|
+
### 1. SDK Initialization
|
|
17
|
+
|
|
18
|
+
Initialize the SDK when the app starts (usually in the App component's useEffect):
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import { initSDK } from 'expo-gaode-map';
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
initSDK({
|
|
25
|
+
androidKey: 'your-android-api-key',
|
|
26
|
+
iosKey: 'your-ios-api-key',
|
|
27
|
+
});
|
|
28
|
+
}, []);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### 2. Permission Check and Request
|
|
32
|
+
|
|
33
|
+
Before using location features, you must check and request permissions:
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import {
|
|
37
|
+
checkLocationPermission,
|
|
38
|
+
requestLocationPermission
|
|
39
|
+
} from 'expo-gaode-map';
|
|
40
|
+
|
|
41
|
+
// Check permission status
|
|
42
|
+
const status = await checkLocationPermission();
|
|
43
|
+
console.log('Permission status:', status);
|
|
44
|
+
// { granted: boolean, canAskAgain: boolean }
|
|
45
|
+
|
|
46
|
+
// Request permission
|
|
47
|
+
if (!status.granted) {
|
|
48
|
+
const result = await requestLocationPermission();
|
|
49
|
+
if (result.granted) {
|
|
50
|
+
console.log('Permission granted');
|
|
51
|
+
} else {
|
|
52
|
+
console.log('Permission denied');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 3. Get Location
|
|
58
|
+
|
|
59
|
+
After permission is granted, you can get the current location:
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
import { getCurrentLocation } from 'expo-gaode-map';
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
const location = await getCurrentLocation();
|
|
66
|
+
console.log('Current location:', location);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error('Get location failed:', error);
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Permission Management
|
|
73
|
+
|
|
74
|
+
### Permission APIs
|
|
75
|
+
|
|
76
|
+
| API | Description | Return Value |
|
|
77
|
+
|-----|-------------|--------------|
|
|
78
|
+
| `checkLocationPermission()` | Check location permission status | `Promise<PermissionStatus>` |
|
|
79
|
+
| `requestLocationPermission()` | Request location permission | `Promise<PermissionStatus>` |
|
|
80
|
+
|
|
81
|
+
### PermissionStatus Type
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
interface PermissionStatus {
|
|
85
|
+
granted: boolean; // Whether permission is granted
|
|
86
|
+
canAskAgain: boolean; // Whether can request again
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Permission Status Explanation
|
|
91
|
+
|
|
92
|
+
- **granted: true** - User granted permission, can use location features
|
|
93
|
+
- **granted: false, canAskAgain: true** - User denied permission, but can request again
|
|
94
|
+
- **granted: false, canAskAgain: false** - User permanently denied permission, need to guide user to settings
|
|
95
|
+
|
|
96
|
+
## Complete Example
|
|
97
|
+
|
|
98
|
+
### Recommended Initialization Process
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
import { useEffect, useState } from 'react';
|
|
102
|
+
import { Alert, Platform, Linking } from 'react-native';
|
|
103
|
+
import {
|
|
104
|
+
MapView,
|
|
105
|
+
initSDK,
|
|
106
|
+
checkLocationPermission,
|
|
107
|
+
requestLocationPermission,
|
|
108
|
+
getCurrentLocation,
|
|
109
|
+
type LatLng,
|
|
110
|
+
} from 'expo-gaode-map';
|
|
111
|
+
|
|
112
|
+
export default function App() {
|
|
113
|
+
const [initialPosition, setInitialPosition] = useState<{
|
|
114
|
+
target: LatLng;
|
|
115
|
+
zoom: number;
|
|
116
|
+
} | null>(null);
|
|
117
|
+
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
const initializeApp = async () => {
|
|
120
|
+
try {
|
|
121
|
+
// 1. Initialize SDK
|
|
122
|
+
console.log('Initializing AMap SDK...');
|
|
123
|
+
initSDK({
|
|
124
|
+
androidKey: 'your-android-api-key',
|
|
125
|
+
iosKey: 'your-ios-api-key',
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// 2. Check permission
|
|
129
|
+
const status = await checkLocationPermission();
|
|
130
|
+
|
|
131
|
+
// 3. Request permission if needed
|
|
132
|
+
if (!status.granted) {
|
|
133
|
+
const result = await requestLocationPermission();
|
|
134
|
+
|
|
135
|
+
if (!result.granted) {
|
|
136
|
+
// Permission denied, use default location
|
|
137
|
+
console.log('Location permission denied, using default location');
|
|
138
|
+
setInitialPosition({
|
|
139
|
+
target: { latitude: 39.90923, longitude: 116.397428 },
|
|
140
|
+
zoom: 10
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Guide user to settings if cannot ask again
|
|
144
|
+
if (!result.canAskAgain) {
|
|
145
|
+
Alert.alert(
|
|
146
|
+
'Location Permission Required',
|
|
147
|
+
'Please enable location permission in settings',
|
|
148
|
+
[
|
|
149
|
+
{ text: 'Cancel', style: 'cancel' },
|
|
150
|
+
{ text: 'Settings', onPress: () => {
|
|
151
|
+
if (Platform.OS === 'ios') {
|
|
152
|
+
Linking.openURL('app-settings:');
|
|
153
|
+
} else {
|
|
154
|
+
Linking.openSettings();
|
|
155
|
+
}
|
|
156
|
+
}}
|
|
157
|
+
]
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// 4. Get current location
|
|
165
|
+
const location = await getCurrentLocation();
|
|
166
|
+
console.log('Current location:', location);
|
|
167
|
+
|
|
168
|
+
// 5. Set map initial position
|
|
169
|
+
setInitialPosition({
|
|
170
|
+
target: {
|
|
171
|
+
latitude: location.latitude,
|
|
172
|
+
longitude: location.longitude
|
|
173
|
+
},
|
|
174
|
+
zoom: 15
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
} catch (error) {
|
|
178
|
+
console.error('Initialization failed:', error);
|
|
179
|
+
// Use default location
|
|
180
|
+
setInitialPosition({
|
|
181
|
+
target: { latitude: 39.90923, longitude: 116.397428 },
|
|
182
|
+
zoom: 10
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
initializeApp();
|
|
188
|
+
}, []);
|
|
189
|
+
|
|
190
|
+
// Wait for initialization
|
|
191
|
+
if (!initialPosition) {
|
|
192
|
+
return <LoadingScreen />;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<MapView
|
|
197
|
+
style={{ flex: 1 }}
|
|
198
|
+
initialCameraPosition={initialPosition}
|
|
199
|
+
myLocationEnabled={true}
|
|
200
|
+
onLoad={() => console.log('Map loaded')}
|
|
201
|
+
/>
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Key Points
|
|
207
|
+
|
|
208
|
+
1. **Initialization Order**:
|
|
209
|
+
```
|
|
210
|
+
initSDK → checkPermission → requestPermission → getCurrentLocation → Render Map
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
2. **Permission Handling**:
|
|
214
|
+
- ✅ Always check permission status first
|
|
215
|
+
- ✅ Only request permission when needed
|
|
216
|
+
- ✅ Handle permission denial cases
|
|
217
|
+
- ✅ Provide default location as fallback
|
|
218
|
+
|
|
219
|
+
3. **Map Rendering**:
|
|
220
|
+
- ✅ **Important**: Wait for `initialPosition` to be set before rendering MapView
|
|
221
|
+
- ✅ Use `initialCameraPosition` to set initial position
|
|
222
|
+
- ⚠️ **iOS Note**: If map is rendered before getting location, it will show default location (Beijing) first then jump, causing flicker
|
|
223
|
+
- ✅ Both Android and iOS will directly position to specified location when map is displayed
|
|
224
|
+
|
|
225
|
+
## Common Issues
|
|
226
|
+
|
|
227
|
+
### Q: How to handle user denying permission?
|
|
228
|
+
|
|
229
|
+
**A:** Provide default location and guide user:
|
|
230
|
+
|
|
231
|
+
```tsx
|
|
232
|
+
if (!result.granted) {
|
|
233
|
+
// Use default location
|
|
234
|
+
setInitialPosition({
|
|
235
|
+
target: { latitude: 39.90923, longitude: 116.397428 },
|
|
236
|
+
zoom: 10
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// Guide to settings if cannot ask again
|
|
240
|
+
if (!result.canAskAgain) {
|
|
241
|
+
Alert.alert(
|
|
242
|
+
'Location Permission Required',
|
|
243
|
+
'Please enable location permission in settings',
|
|
244
|
+
[
|
|
245
|
+
{ text: 'Cancel' },
|
|
246
|
+
{ text: 'Settings', onPress: () => Linking.openSettings() }
|
|
247
|
+
]
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Q: Can I update location after map is loaded?
|
|
254
|
+
|
|
255
|
+
**A:** Yes, use the `moveCamera` method:
|
|
256
|
+
|
|
257
|
+
```tsx
|
|
258
|
+
const mapRef = useRef<MapViewRef>(null);
|
|
259
|
+
|
|
260
|
+
// Update map center
|
|
261
|
+
await mapRef.current?.moveCamera({
|
|
262
|
+
target: { latitude: 40.0, longitude: 116.5 },
|
|
263
|
+
zoom: 15,
|
|
264
|
+
}, 1000); // 1 second animation
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Q: How to configure location parameters?
|
|
268
|
+
|
|
269
|
+
**A:** Use the `configure` function, **must be called after `initSDK`**:
|
|
270
|
+
|
|
271
|
+
```tsx
|
|
272
|
+
import { initSDK, configure } from 'expo-gaode-map';
|
|
273
|
+
|
|
274
|
+
// 1. Initialize SDK first
|
|
275
|
+
initSDK({
|
|
276
|
+
androidKey: 'your-android-api-key',
|
|
277
|
+
iosKey: 'your-ios-api-key',
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// 2. Then configure location parameters
|
|
281
|
+
configure({
|
|
282
|
+
withReGeocode: true, // Return address info
|
|
283
|
+
mode: 0, // High accuracy mode
|
|
284
|
+
interval: 2000, // Update every 2 seconds
|
|
285
|
+
});
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
> ⚠️ **Important**: `configure` must be called after `initSDK`, otherwise configuration may not take effect.
|
|
289
|
+
|
|
290
|
+
### Q: Are there differences between Android and iOS initialization?
|
|
291
|
+
|
|
292
|
+
**A:** The initialization process is the same, but there are differences:
|
|
293
|
+
|
|
294
|
+
**Android:**
|
|
295
|
+
- Need to configure permissions in `AndroidManifest.xml`
|
|
296
|
+
- Support more location configuration options
|
|
297
|
+
|
|
298
|
+
**iOS:**
|
|
299
|
+
- Need to configure permission descriptions in `Info.plist`
|
|
300
|
+
- Support background location and heading updates
|
|
301
|
+
|
|
302
|
+
For detailed configuration, see [AMap Official Documentation](https://lbs.amap.com/).
|
|
303
|
+
|
|
304
|
+
## Best Practices
|
|
305
|
+
|
|
306
|
+
1. **Always Handle Permissions**:
|
|
307
|
+
```tsx
|
|
308
|
+
// ✅ Good practice
|
|
309
|
+
const status = await checkLocationPermission();
|
|
310
|
+
if (!status.granted) {
|
|
311
|
+
await requestLocationPermission();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// ❌ Bad practice
|
|
315
|
+
await getCurrentLocation(); // May fail due to no permission
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
2. **Provide Loading State**:
|
|
319
|
+
```tsx
|
|
320
|
+
if (!initialPosition) {
|
|
321
|
+
return <LoadingScreen />;
|
|
322
|
+
}
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
3. **Error Handling**:
|
|
326
|
+
```tsx
|
|
327
|
+
try {
|
|
328
|
+
const location = await getCurrentLocation();
|
|
329
|
+
} catch (error) {
|
|
330
|
+
console.error('Get location failed:', error);
|
|
331
|
+
// Use default location
|
|
332
|
+
}
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
4. **Avoid Repeated Initialization**:
|
|
336
|
+
```tsx
|
|
337
|
+
useEffect(() => {
|
|
338
|
+
initSDK({ ... });
|
|
339
|
+
}, []); // Empty dependency array, initialize only once
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
## Related Documentation
|
|
343
|
+
|
|
344
|
+
- [API Documentation](./API.en.md) - Complete API reference
|
|
345
|
+
- [Usage Examples](./EXAMPLES.en.md) - Detailed code examples
|
|
346
|
+
- [README](../README.md) - Quick start guide
|
package/docs/INITIALIZATION.md
CHANGED
package/expo-module.config.json
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"platforms": ["apple", "android"],
|
|
3
3
|
"apple": {
|
|
4
|
-
"modules": [
|
|
4
|
+
"modules": [
|
|
5
|
+
"ExpoGaodeMapModule",
|
|
6
|
+
"ExpoGaodeMapViewModule",
|
|
7
|
+
"MarkerViewModule",
|
|
8
|
+
"CircleViewModule",
|
|
9
|
+
"PolygonViewModule",
|
|
10
|
+
"PolylineViewModule",
|
|
11
|
+
"MultiPointViewModule",
|
|
12
|
+
"HeatMapViewModule",
|
|
13
|
+
"ClusterViewModule"
|
|
14
|
+
]
|
|
5
15
|
},
|
|
6
16
|
"android": {
|
|
7
|
-
"modules": [
|
|
17
|
+
"modules": [
|
|
18
|
+
"expo.modules.gaodemap.ExpoGaodeMapModule",
|
|
19
|
+
"expo.modules.gaodemap.ExpoGaodeMapViewModule",
|
|
20
|
+
"expo.modules.gaodemap.overlays.MarkerViewModule",
|
|
21
|
+
"expo.modules.gaodemap.overlays.CircleViewModule",
|
|
22
|
+
"expo.modules.gaodemap.overlays.PolygonViewModule",
|
|
23
|
+
"expo.modules.gaodemap.overlays.PolylineViewModule",
|
|
24
|
+
"expo.modules.gaodemap.overlays.MultiPointViewModule",
|
|
25
|
+
"expo.modules.gaodemap.overlays.HeatMapViewModule",
|
|
26
|
+
"expo.modules.gaodemap.overlays.ClusterViewModule"
|
|
27
|
+
]
|
|
8
28
|
}
|
|
9
29
|
}
|