expo-gaode-map 2.2.11 → 2.2.12
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/android/build.gradle +2 -2
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapModule.kt +3 -0
- package/android/src/main/java/expo/modules/gaodemap/ExpoGaodeMapViewModule.kt +1 -1
- package/android/src/main/java/expo/modules/gaodemap/utils/PermissionHelper.kt +1 -0
- package/build/index.d.ts +10 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +17 -0
- package/build/index.js.map +1 -1
- package/build/types/common.types.d.ts +2 -3
- package/build/types/common.types.d.ts.map +1 -1
- package/build/types/common.types.js +0 -4
- package/build/types/common.types.js.map +1 -1
- package/build/utils/ErrorHandler.d.ts.map +1 -1
- package/build/utils/ErrorHandler.js +37 -15
- package/build/utils/ErrorHandler.js.map +1 -1
- package/package.json +15 -16
- package/plugin/build/withGaodeMap.js +61 -66
package/android/build.gradle
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
apply plugin: 'com.android.library'
|
|
2
2
|
|
|
3
3
|
group = 'expo.modules.gaodemap'
|
|
4
|
-
version = '
|
|
4
|
+
version = '2.2.11'
|
|
5
5
|
|
|
6
6
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
7
7
|
apply from: expoModulesCorePlugin
|
|
@@ -35,7 +35,7 @@ android {
|
|
|
35
35
|
namespace "expo.modules.gaodemap"
|
|
36
36
|
defaultConfig {
|
|
37
37
|
versionCode 1
|
|
38
|
-
versionName "
|
|
38
|
+
versionName "2.2.11"
|
|
39
39
|
}
|
|
40
40
|
lintOptions {
|
|
41
41
|
abortOnError false
|
|
@@ -341,6 +341,7 @@ class ExpoGaodeMapModule : Module() {
|
|
|
341
341
|
|
|
342
342
|
promise.resolve(mapOf(
|
|
343
343
|
"granted" to foregroundStatus.granted,
|
|
344
|
+
"status" to if (foregroundStatus.granted) "granted" else if (foregroundStatus.isPermanentlyDenied) "denied" else "notDetermined",
|
|
344
345
|
"fineLocation" to foregroundStatus.fineLocation,
|
|
345
346
|
"coarseLocation" to foregroundStatus.coarseLocation,
|
|
346
347
|
"backgroundLocation" to backgroundStatus.backgroundLocation,
|
|
@@ -386,6 +387,7 @@ class ExpoGaodeMapModule : Module() {
|
|
|
386
387
|
handler.removeCallbacks(this)
|
|
387
388
|
promise.resolve(mapOf(
|
|
388
389
|
"granted" to status.granted,
|
|
390
|
+
"status" to if (status.granted) "granted" else if (status.isPermanentlyDenied) "denied" else "notDetermined",
|
|
389
391
|
"fineLocation" to status.fineLocation,
|
|
390
392
|
"coarseLocation" to status.coarseLocation,
|
|
391
393
|
"shouldShowRationale" to status.shouldShowRationale,
|
|
@@ -455,6 +457,7 @@ class ExpoGaodeMapModule : Module() {
|
|
|
455
457
|
handler.removeCallbacks(this)
|
|
456
458
|
promise.resolve(mapOf(
|
|
457
459
|
"granted" to status.granted,
|
|
460
|
+
"status" to if (status.granted) "granted" else if (status.isPermanentlyDenied) "denied" else "notDetermined",
|
|
458
461
|
"backgroundLocation" to status.backgroundLocation,
|
|
459
462
|
"shouldShowRationale" to status.shouldShowRationale,
|
|
460
463
|
"isPermanentlyDenied" to status.isPermanentlyDenied
|
|
@@ -13,7 +13,7 @@ class ExpoGaodeMapViewModule : Module() {
|
|
|
13
13
|
View(ExpoGaodeMapView::class) {
|
|
14
14
|
Events("onMapPress", "onMapLongPress", "onLoad", "onLocation", "onCameraMove", "onCameraIdle")
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
|
|
18
18
|
// 延迟销毁地图,避免页面退出动画未完成时地图就变成白屏
|
|
19
19
|
OnViewDestroys { view: ExpoGaodeMapView ->
|
package/build/index.d.ts
CHANGED
|
@@ -14,6 +14,16 @@ export { FoldableMapView, useFoldableMap, } from './components/FoldableMapView';
|
|
|
14
14
|
export type { FoldableMapViewProps, FoldableConfig, } from './components/FoldableMapView';
|
|
15
15
|
export { default as ExpoGaodeMapOfflineModule } from './utils/OfflineMapManager';
|
|
16
16
|
export type { OfflineMapInfo, OfflineMapStatus, OfflineMapDownloadConfig, OfflineMapDownloadEvent, OfflineMapCompleteEvent, OfflineMapErrorEvent, OfflineMapPausedEvent, OfflineMapCancelledEvent, OfflineMapStorageInfo, OfflineMapEvents, } from './types/offline.types';
|
|
17
|
+
/**
|
|
18
|
+
* Check or request permissions to access the location.
|
|
19
|
+
* This uses both `requestPermissionsAsync` and `getPermissionsAsync` to interact with the permissions.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const [status, requestPermission] = useLocationPermissions();
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const useLocationPermissions: (options?: import("expo-modules-core").PermissionHookOptions<object> | undefined) => [import("./types").PermissionStatus | null, () => Promise<import("./types").PermissionStatus>, () => Promise<import("./types").PermissionStatus>];
|
|
17
27
|
export { getSDKConfig, getWebKey } from './ExpoGaodeMapModule';
|
|
18
28
|
export { default } from './ExpoGaodeMapModule';
|
|
19
29
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,cAAc,SAAS,CAAC;AAExB,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAGrE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACxD,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,EACL,MAAM,EACN,QAAQ,EACR,OAAO,EACP,MAAM,EACN,OAAO,EACP,UAAU,EACV,OAAO,GACR,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,YAAY,EACZ,WAAW,EACX,aAAa,EACb,SAAS,GACV,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,SAAS,EACT,eAAe,EACf,WAAW,EACX,QAAQ,EACR,UAAU,EACV,MAAM,GACP,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAG1E,OAAO,EACL,eAAe,EACf,iBAAiB,EAAE,UAAU;AAC7B,sBAAsB,GACvB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,eAAe,EACf,cAAc,GACf,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACV,oBAAoB,EACpB,cAAc,GACf,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAEjF,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAM/B;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,wOAGjC,CAAA;AAGF,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAG/D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createPermissionHook } from 'expo-modules-core';
|
|
2
|
+
import ExpoGaodeMapModuleWithHelpers from './ExpoGaodeMapModule';
|
|
1
3
|
// 导出类型定义(包含所有通用类型)
|
|
2
4
|
export * from './types';
|
|
3
5
|
// 导出原生模块
|
|
@@ -19,6 +21,21 @@ LocationPermissionType, } from './utils/PermissionUtils';
|
|
|
19
21
|
export { FoldableMapView, useFoldableMap, } from './components/FoldableMapView';
|
|
20
22
|
// 导出离线地图 API
|
|
21
23
|
export { default as ExpoGaodeMapOfflineModule } from './utils/OfflineMapManager';
|
|
24
|
+
const requestPermissionsAsync = ExpoGaodeMapModuleWithHelpers.requestLocationPermission;
|
|
25
|
+
const getPermissionsAsync = ExpoGaodeMapModuleWithHelpers.checkLocationPermission;
|
|
26
|
+
/**
|
|
27
|
+
* Check or request permissions to access the location.
|
|
28
|
+
* This uses both `requestPermissionsAsync` and `getPermissionsAsync` to interact with the permissions.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const [status, requestPermission] = useLocationPermissions();
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export const useLocationPermissions = createPermissionHook({
|
|
36
|
+
getMethod: getPermissionsAsync,
|
|
37
|
+
requestMethod: requestPermissionsAsync,
|
|
38
|
+
});
|
|
22
39
|
// 导出便捷读取的 SDK 配置与 webKey
|
|
23
40
|
export { getSDKConfig, getWebKey } from './ExpoGaodeMapModule';
|
|
24
41
|
// 默认导出原生模块
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,6BAA6B,MAAM,sBAAsB,CAAC;AAGjE,mBAAmB;AACnB,cAAc,SAAS,CAAC;AACxB,SAAS;AACT,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAErE,WAAW;AACX,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGxD,UAAU;AACV,OAAO,EACL,MAAM,EACN,QAAQ,EACR,OAAO,EACP,MAAM,EACN,OAAO,EACP,UAAU,EACV,OAAO,GACR,MAAM,uBAAuB,CAAC;AAE/B,WAAW;AACX,OAAO,EACL,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAE9B,WAAW;AACX,OAAO,EACL,YAAY,EACZ,WAAW,EACX,aAAa,EACb,SAAS,GACV,MAAM,sBAAsB,CAAC;AAG9B,WAAW;AACX,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,SAAS,EACT,eAAe,EACf,WAAW,EACX,QAAQ,EACR,UAAU,EACV,MAAM,GACP,MAAM,0BAA0B,CAAC;AAGlC,gDAAgD;AAChD,OAAO,EACL,eAAe,EACf,iBAAiB,EAAE,UAAU;AAC7B,sBAAsB,GACvB,MAAM,yBAAyB,CAAC;AAEjC,YAAY;AACZ,OAAO,EACL,eAAe,EACf,cAAc,GACf,MAAM,8BAA8B,CAAC;AAMtC,aAAa;AACb,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAejF,MAAM,uBAAuB,GAAG,6BAA6B,CAAC,yBAAyB,CAAA;AACvF,MAAM,mBAAmB,GAAG,6BAA6B,CAAC,uBAAuB,CAAA;AAGjF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;IACzD,SAAS,EAAE,mBAAmB;IAC9B,aAAa,EAAE,uBAAuB;CACvC,CAAC,CAAA;AAEF,yBAAyB;AACzB,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAE/D,WAAW;AACX,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["\nimport { createPermissionHook } from 'expo-modules-core';\nimport ExpoGaodeMapModuleWithHelpers from './ExpoGaodeMapModule';\n\n\n// 导出类型定义(包含所有通用类型)\nexport * from './types';\n// 导出原生模块\nexport { default as ExpoGaodeMapModule } from './ExpoGaodeMapModule';\n\n// 导出地图视图组件\nexport { default as MapView } from './ExpoGaodeMapView';\nexport type { MapViewRef } from './ExpoGaodeMapView';\n\n// 导出覆盖物组件\nexport {\n Marker,\n Polyline,\n Polygon,\n Circle,\n HeatMap,\n MultiPoint,\n Cluster,\n} from './components/overlays';\n\n// 导出模块检测工具\nexport {\n requireModule,\n OptionalModules,\n getInstalledModules,\n printModuleInfo,\n createLazyLoader,\n} from './utils/ModuleLoader';\n\n// 导出错误处理工具\nexport {\n ErrorHandler,\n ErrorLogger,\n GaodeMapError,\n ErrorType,\n} from './utils/ErrorHandler';\nexport type { ErrorDetails } from './utils/ErrorHandler';\n\n// 导出平台检测工具\nexport {\n PlatformDetector,\n DeviceType,\n FoldState,\n isAndroid14Plus,\n isiOS17Plus,\n isTablet,\n isFoldable,\n isIPad,\n} from './utils/PlatformDetector';\nexport type { DeviceInfo, SystemVersion } from './utils/PlatformDetector';\n\n// 导出权限工具类(仅提供文案和诊断,实际权限请求使用 ExpoGaodeMapModule)\nexport {\n PermissionUtils,\n PermissionManager, // 向后兼容的别名\n LocationPermissionType,\n} from './utils/PermissionUtils';\n\n// 导出折叠屏适配组件\nexport {\n FoldableMapView,\n useFoldableMap,\n} from './components/FoldableMapView';\nexport type {\n FoldableMapViewProps,\n FoldableConfig,\n} from './components/FoldableMapView';\n\n// 导出离线地图 API\nexport { default as ExpoGaodeMapOfflineModule } from './utils/OfflineMapManager';\n\nexport type {\n OfflineMapInfo,\n OfflineMapStatus,\n OfflineMapDownloadConfig,\n OfflineMapDownloadEvent,\n OfflineMapCompleteEvent,\n OfflineMapErrorEvent,\n OfflineMapPausedEvent,\n OfflineMapCancelledEvent,\n OfflineMapStorageInfo,\n OfflineMapEvents,\n} from './types/offline.types';\n\nconst requestPermissionsAsync = ExpoGaodeMapModuleWithHelpers.requestLocationPermission\nconst getPermissionsAsync = ExpoGaodeMapModuleWithHelpers.checkLocationPermission\n\n\n/**\n * Check or request permissions to access the location.\n * This uses both `requestPermissionsAsync` and `getPermissionsAsync` to interact with the permissions.\n *\n * @example\n * ```ts\n * const [status, requestPermission] = useLocationPermissions();\n * ```\n */\nexport const useLocationPermissions = createPermissionHook({\n getMethod: getPermissionsAsync,\n requestMethod: requestPermissionsAsync,\n})\n\n// 导出便捷读取的 SDK 配置与 webKey\nexport { getSDKConfig, getWebKey } from './ExpoGaodeMapModule';\n\n// 默认导出原生模块\nexport { default } from './ExpoGaodeMapModule';\n"]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* 高德地图通用类型定义
|
|
3
3
|
* 基于 Expo Modules API
|
|
4
4
|
*/
|
|
5
|
+
import { PermissionResponse } from 'expo-modules-core';
|
|
5
6
|
/**
|
|
6
7
|
* SDK 配置参数
|
|
7
8
|
*/
|
|
@@ -16,11 +17,9 @@ export interface SDKConfig {
|
|
|
16
17
|
/**
|
|
17
18
|
* 权限状态(增强版,支持 Android 14+ 和 iOS 17+)
|
|
18
19
|
*/
|
|
19
|
-
export interface PermissionStatus {
|
|
20
|
+
export interface PermissionStatus extends PermissionResponse {
|
|
20
21
|
/** 是否已授权(前台位置权限) */
|
|
21
22
|
granted: boolean;
|
|
22
|
-
/** iOS 权限状态字符串 */
|
|
23
|
-
status?: 'notDetermined' | 'restricted' | 'denied' | 'authorizedAlways' | 'authorizedWhenInUse' | 'unknown';
|
|
24
23
|
/** Android 精确位置权限 */
|
|
25
24
|
fineLocation?: boolean;
|
|
26
25
|
/** Android 粗略位置权限 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.types.d.ts","sourceRoot":"","sources":["../../src/types/common.types.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"common.types.d.ts","sourceRoot":"","sources":["../../src/types/common.types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAC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ACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,oBAAY,OAAO;IACjB;;OAEG;IACH,QAAQ,IAAI;IAEZ;;OAEG;IACH,SAAS,IAAI;IAEb;;OAEG;IACH,KAAK,IAAI;IAET;;OAEG;IACH,IAAI,IAAI;IAER;;;OAGG;IACH,GAAG,IAAI;CACR;AAED;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.types.js","sourceRoot":"","sources":["../../src/types/common.types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"common.types.js","sourceRoot":"","sources":["../../src/types/common.types.ts"],"names":[],"mappings":"AA+HA;;GAEG;AACH,MAAM,CAAN,IAAY,OA0BX;AA1BD,WAAY,OAAO;IACjB;;OAEG;IACH,6CAAY,CAAA;IAEZ;;OAEG;IACH,+CAAa,CAAA;IAEb;;OAEG;IACH,uCAAS,CAAA;IAET;;OAEG;IACH,qCAAQ,CAAA;IAER;;;OAGG;IACH,mCAAO,CAAA;AACT,CAAC,EA1BW,OAAO,KAAP,OAAO,QA0BlB","sourcesContent":["/**\n * 高德地图通用类型定义\n * 基于 Expo Modules API\n */\nimport { PermissionResponse } from 'expo-modules-core';\n\n/**\n * SDK 配置参数\n */\nexport interface SDKConfig {\n /** Android 平台的高德地图 API Key */\n androidKey?: string;\n /** iOS 平台的高德地图 API Key */\n iosKey?: string;\n /** web api key 如果要使用expo-gaode-map-web-api相关的功能,需要配置web api key*/\n webKey?: string;\n}\n\n/**\n * 权限状态(增强版,支持 Android 14+ 和 iOS 17+)\n */\nexport interface PermissionStatus extends PermissionResponse{\n /** 是否已授权(前台位置权限) */\n granted: boolean;\n \n // Android 专用字段\n /** Android 精确位置权限 */\n fineLocation?: boolean;\n /** Android 粗略位置权限 */\n coarseLocation?: boolean;\n /** Android 后台位置权限(Android 10+) */\n backgroundLocation?: boolean;\n /** 是否应显示权限说明(Android) */\n shouldShowRationale?: boolean;\n /** 权限是否被永久拒绝(Android) */\n isPermanentlyDenied?: boolean;\n /** 是否为 Android 14+(Android) */\n isAndroid14Plus?: boolean;\n \n // 其他字段\n /** 额外的消息说明 */\n message?: string;\n}\n\n/**\n * 点坐标(屏幕坐标)\n */\nexport interface Point {\n x: number;\n y: number;\n}\n\n/**\n * 地理坐标\n */\nexport interface LatLng {\n /**\n * 纬度\n */\n latitude: number;\n\n /**\n * 经度\n */\n longitude: number;\n}\n\n/**\n * 地图标注点(POI)\n */\nexport interface MapPoi {\n /**\n * 标注点 ID\n */\n id: string;\n\n /**\n * 标注点名称\n */\n name: string;\n\n /**\n * 标注点坐标\n */\n position: LatLng;\n}\n\n/**\n * 矩形坐标边界\n */\nexport interface LatLngBounds {\n /**\n * 西南坐标\n */\n southwest: LatLng;\n\n /**\n * 东北坐标\n */\n northeast: LatLng;\n}\n\n/**\n * 地图相机位置\n */\nexport interface CameraPosition {\n /**\n * 中心坐标\n */\n target?: LatLng;\n\n /**\n * 缩放级别(3-20)\n */\n zoom?: number;\n\n /**\n * 朝向、旋转角度(0-360度)\n */\n bearing?: number;\n\n /**\n * 倾斜角度(0-60度)\n */\n tilt?: number;\n}\n\n/**\n * 地图类型\n */\nexport enum MapType {\n /**\n * 标准地图\n */\n Standard = 0,\n\n /**\n * 卫星地图\n */\n Satellite = 1,\n\n /**\n * 夜间地图\n */\n Night = 2,\n\n /**\n * 导航地图\n */\n Navi = 3,\n\n /**\n * 公交地图\n * @platform android\n */\n Bus = 4,\n}\n\n/**\n * 颜色值类型\n * 支持:\n * - 十六进制字符串: '#AARRGGBB' 或 '#RRGGBB'\n * - 数字格式: 0xAARRGGBB (用于 Android)\n */\nexport type ColorValue = string | number;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorHandler.d.ts","sourceRoot":"","sources":["../../src/utils/ErrorHandler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,oBAAY,SAAS;IACnB,eAAe;IACf,mBAAmB,wBAAwB;IAC3C,mBAAmB;IACnB,eAAe,oBAAoB;IACnC,YAAY;IACZ,iBAAiB,sBAAsB;IACvC,WAAW;IACX,eAAe,oBAAoB;IACnC,cAAc;IACd,yBAAyB,8BAA8B;IACvD,eAAe;IACf,wBAAwB,6BAA6B;IACrD,WAAW;IACX,iBAAiB,sBAAsB;IACvC,WAAW;IACX,aAAa,kBAAkB;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,WAAW;IACX,IAAI,EAAE,SAAS,CAAC;IAChB,WAAW;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW;IACX,aAAa,CAAC,EAAE,KAAK,CAAC;CACvB;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,KAAK,CAAC;gBAEV,OAAO,EAAE,YAAY;CAqBlC;AAED;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,UAAU,CAA4C;IAErE;;OAEG;IACH,MAAM,CAAC,iBAAiB,IAAI,aAAa;IAwBzC;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,QAAQ,EAAE,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,aAAa;
|
|
1
|
+
{"version":3,"file":"ErrorHandler.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uCrD;;OAEG;IACH,MAAM,CAAC,uBAAuB,IAAI,aAAa;IA+B/C;;OAEG;IACH,MAAM,CAAC,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa;IAqC/D;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,aAAa;IAgB1F;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,aAAa,CAAC,EAAE,KAAK,GAAG,aAAa;IAmBzD;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,aAAa;CAkDnE;AAED;;GAEG;AACH,qBAAa,WAAW;IAEtB,OAAO,CAAC,MAAM,CAAC,SAAS,CAAmD;IAE3E;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO;IAIlC;;OAEG;IACH,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,aAAa;IAU/B;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;CAK3C"}
|
|
@@ -97,14 +97,22 @@ useEffect(() => {
|
|
|
97
97
|
return new GaodeMapError({
|
|
98
98
|
type: ErrorType.INVALID_API_KEY,
|
|
99
99
|
message: `${platformText} API Key 配置错误或未配置`,
|
|
100
|
-
solution:
|
|
100
|
+
solution: `⚠️ API Key 与 Bundle ID 不匹配是最常见的原因!
|
|
101
|
+
|
|
102
|
+
请检查以下步骤:
|
|
101
103
|
|
|
102
|
-
1️⃣
|
|
104
|
+
1️⃣ 确认 API Key 的配置:
|
|
103
105
|
• 访问高德开放平台:https://lbs.amap.com/
|
|
104
|
-
•
|
|
105
|
-
•
|
|
106
|
+
• 检查您的应用配置中的 Bundle ID 是否与当前项目一致
|
|
107
|
+
• iOS Bundle ID:在 Xcode → Target → General → Bundle Identifier 查看
|
|
108
|
+
• Android 包名:在 android/app/build.gradle → applicationId 查看
|
|
106
109
|
|
|
107
|
-
2️⃣
|
|
110
|
+
2️⃣ 重新创建正确的 API Key(如果 Bundle ID 不同):
|
|
111
|
+
• 在高德开放平台创建新应用
|
|
112
|
+
• 填写正确的 Bundle ID(iOS)或包名(Android)
|
|
113
|
+
• 获取新的 API Key
|
|
114
|
+
|
|
115
|
+
3️⃣ 配置 API Key(推荐使用 Config Plugin):
|
|
108
116
|
|
|
109
117
|
在 app.json 中配置:
|
|
110
118
|
{
|
|
@@ -125,7 +133,7 @@ useEffect(() => {
|
|
|
125
133
|
npx expo prebuild --clean
|
|
126
134
|
npx expo run:${platform === 'ios' ? 'ios' : 'android'}
|
|
127
135
|
|
|
128
|
-
|
|
136
|
+
4️⃣ 或在代码中配置:
|
|
129
137
|
ExpoGaodeMapModule.initSDK({
|
|
130
138
|
androidKey: 'your-android-key',
|
|
131
139
|
iosKey: 'your-ios-key',
|
|
@@ -191,15 +199,28 @@ const checkPermission = async () => {
|
|
|
191
199
|
return new GaodeMapError({
|
|
192
200
|
type: ErrorType.LOCATION_FAILED,
|
|
193
201
|
message: `定位失败${reason ? `:${reason}` : ''}`,
|
|
194
|
-
solution:
|
|
202
|
+
solution: `⚠️ 最常见原因:API Key 与 Bundle ID 不匹配!
|
|
195
203
|
|
|
196
|
-
|
|
197
|
-
2️⃣ 网络连接是否正常
|
|
198
|
-
3️⃣ 定位权限是否已授予
|
|
199
|
-
4️⃣ 是否在室内或信号较弱的地方
|
|
204
|
+
请按以下顺序排查:
|
|
200
205
|
|
|
201
|
-
|
|
202
|
-
|
|
206
|
+
1️⃣ 检查 API Key 配置(最常见问题):
|
|
207
|
+
• 访问高德开放平台:https://lbs.amap.com/
|
|
208
|
+
• 确认您的应用的 Bundle ID 与当前项目一致
|
|
209
|
+
• iOS Bundle ID:在 Xcode → Target → General → Bundle Identifier
|
|
210
|
+
• Android 包名:在 android/app/build.gradle → applicationId
|
|
211
|
+
|
|
212
|
+
如果 Bundle ID 不同,必须在高德平台重新创建应用并获取新 Key
|
|
213
|
+
|
|
214
|
+
2️⃣ 检查设备 GPS 和网络:
|
|
215
|
+
• 确认设备 GPS 已开启
|
|
216
|
+
• 检查网络连接是否正常
|
|
217
|
+
• 尝试在室外空旷处测试
|
|
218
|
+
|
|
219
|
+
3️⃣ 检查定位权限:
|
|
220
|
+
• iOS:设置 → 隐私 → 定位服务 → 允许应用访问
|
|
221
|
+
• Android:设置 → 应用 → 权限管理 → 位置信息
|
|
222
|
+
|
|
223
|
+
4️⃣ 配置定位参数(如果 API Key 正确但定位仍失败):
|
|
203
224
|
ExpoGaodeMapModule.setLocationTimeout(30); // 增加超时时间
|
|
204
225
|
ExpoGaodeMapModule.setInterval(2000); // 设置定位间隔
|
|
205
226
|
|
|
@@ -224,7 +245,7 @@ ExpoGaodeMapModule.setDesiredAccuracy(0); // 最佳精度`,
|
|
|
224
245
|
1️⃣ 确认已正确安装:
|
|
225
246
|
npm install expo-gaode-map
|
|
226
247
|
# 或
|
|
227
|
-
|
|
248
|
+
bun install expo-gaode-map
|
|
228
249
|
|
|
229
250
|
2️⃣ 重新构建原生代码:
|
|
230
251
|
npx expo prebuild --clean
|
|
@@ -368,7 +389,8 @@ const App = () => {
|
|
|
368
389
|
* 错误日志工具
|
|
369
390
|
*/
|
|
370
391
|
export class ErrorLogger {
|
|
371
|
-
|
|
392
|
+
// 兼容不同环境:Bun/Jest/Node
|
|
393
|
+
static isEnabled = typeof __DEV__ !== 'undefined' ? __DEV__ : true;
|
|
372
394
|
/**
|
|
373
395
|
* 启用/禁用错误日志
|
|
374
396
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorHandler.js","sourceRoot":"","sources":["../../src/utils/ErrorHandler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,CAAN,IAAY,SAiBX;AAjBD,WAAY,SAAS;IACnB,eAAe;IACf,wDAA2C,CAAA;IAC3C,mBAA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AAM,CAAC,UAAU,CAAC,OAAgB;QAChC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,GAAG,CAAC,KAAoB;QAC7B,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,OAAO;QAE5B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAE7B,IAAI,KAAK,CAAC,aAAa,EAAE,CAAC;YACxB,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,OAAe,EAAE,OAAa;QACxC,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,OAAO;QAE5B,OAAO,CAAC,IAAI,CAAC,uBAAuB,OAAO,EAAE,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;IAChE,CAAC","sourcesContent":["/**\n * 高德地图错误处理工具\n * 提供友好的错误提示和解决方案指引\n */\n\n/**\n * 错误类型枚举\n */\nexport enum ErrorType {\n /** SDK 未初始化 */\n SDK_NOT_INITIALIZED = 'SDK_NOT_INITIALIZED',\n /** API Key 配置错误 */\n INVALID_API_KEY = 'INVALID_API_KEY',\n /** 权限未授予 */\n PERMISSION_DENIED = 'PERMISSION_DENIED',\n /** 定位失败 */\n LOCATION_FAILED = 'LOCATION_FAILED',\n /** 原生模块不可用 */\n NATIVE_MODULE_UNAVAILABLE = 'NATIVE_MODULE_UNAVAILABLE',\n /** 地图视图未初始化 */\n MAP_VIEW_NOT_INITIALIZED = 'MAP_VIEW_NOT_INITIALIZED',\n /** 参数错误 */\n INVALID_PARAMETER = 'INVALID_PARAMETER',\n /** 网络错误 */\n NETWORK_ERROR = 'NETWORK_ERROR',\n}\n\n/**\n * 错误详情接口\n */\nexport interface ErrorDetails {\n /** 错误类型 */\n type: ErrorType;\n /** 错误消息 */\n message: string;\n /** 解决方案 */\n solution: string;\n /** 文档链接 */\n docUrl?: string;\n /** 原始错误 */\n originalError?: Error;\n}\n\n/**\n * 自定义错误类\n */\nexport class GaodeMapError extends Error {\n type: ErrorType;\n solution: string;\n docUrl?: string;\n originalError?: Error;\n\n constructor(details: ErrorDetails) {\n const fullMessage = `\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n🗺️ 高德地图错误 [${details.type}]\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n❌ 错误信息:\n ${details.message}\n\n💡 解决方案:\n ${details.solution}\n\n${details.docUrl ? `📖 详细文档:\\n ${details.docUrl}\\n` : ''}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n`;\n super(fullMessage);\n this.name = 'GaodeMapError';\n this.type = details.type;\n this.solution = details.solution;\n this.docUrl = details.docUrl;\n this.originalError = details.originalError;\n }\n}\n\n/**\n * 错误处理器类\n */\nexport class ErrorHandler {\n private static docBaseUrl = 'https://TomWq.github.io/expo-gaode-map';\n\n /**\n * SDK 未初始化错误\n */\n static sdkNotInitialized(): GaodeMapError {\n return new GaodeMapError({\n type: ErrorType.SDK_NOT_INITIALIZED,\n message: '高德地图 SDK 尚未初始化',\n solution: `请在使用地图功能前先调用 initSDK():\n\nimport ExpoGaodeMapModule from 'expo-gaode-map';\n\nuseEffect(() => {\n // 在组件挂载时初始化\n ExpoGaodeMapModule.initSDK({\n androidKey: 'your-android-key',\n iosKey: 'your-ios-key',\n });\n}, []);\n\n⚠️ 常见原因:\n1. 忘记调用 initSDK() 就使用了定位或地图功能\n2. initSDK() 调用时机过晚(应在 useEffect 中尽早调用)\n3. 使用 Config Plugin 但未重新构建原生代码`,\n docUrl: `${this.docBaseUrl}/guide/initialization.html`,\n });\n }\n\n /**\n * API Key 配置错误\n */\n static invalidApiKey(platform: 'android' | 'ios' | 'both'): GaodeMapError {\n const platformText = {\n android: 'Android',\n ios: 'iOS',\n both: 'Android 和 iOS',\n }[platform];\n\n return new GaodeMapError({\n type: ErrorType.INVALID_API_KEY,\n message: `${platformText} API Key 配置错误或未配置`,\n solution: `请检查以下步骤:\n\n1️⃣ 获取 API Key:\n • 访问高德开放平台:https://lbs.amap.com/\n • 注册并创建应用\n • 获取对应平台的 API Key\n\n2️⃣ 配置 API Key(推荐使用 Config Plugin):\n\n在 app.json 中配置:\n{\n \"expo\": {\n \"plugins\": [\n [\n \"expo-gaode-map\",\n {\n \"androidKey\": \"your-android-key\",\n \"iosKey\": \"your-ios-key\"\n }\n ]\n ]\n }\n}\n\n然后重新构建:\nnpx expo prebuild --clean\nnpx expo run:${platform === 'ios' ? 'ios' : 'android'}\n\n3️⃣ 或在代码中配置:\nExpoGaodeMapModule.initSDK({\n androidKey: 'your-android-key',\n iosKey: 'your-ios-key',\n});`,\n docUrl: `${this.docBaseUrl}/guide/initialization.html`,\n });\n }\n\n /**\n * 权限未授予错误\n */\n static permissionDenied(permissionType: 'location'): GaodeMapError {\n return new GaodeMapError({\n type: ErrorType.PERMISSION_DENIED,\n message: '定位权限未授予,无法使用定位功能',\n solution: `请按以下步骤授予权限:\n\n1️⃣ 请求权限:\nimport ExpoGaodeMapModule from 'expo-gaode-map';\n\nconst checkPermission = async () => {\n // 检查权限状态\n const status = await ExpoGaodeMapModule.checkLocationPermission();\n \n if (!status.granted) {\n // 请求权限\n const result = await ExpoGaodeMapModule.requestLocationPermission();\n \n if (!result.granted) {\n // 用户拒绝授权,引导用户去设置\n Alert.alert(\n '需要定位权限',\n '请在设置中开启定位权限以使用地图功能',\n [\n { text: '取消', style: 'cancel' },\n { text: '去设置', onPress: () => Linking.openSettings() }\n ]\n );\n }\n }\n};\n\n2️⃣ iOS 配置(在 app.json 中):\n{\n \"expo\": {\n \"ios\": {\n \"infoPlist\": {\n \"NSLocationWhenInUseUsageDescription\": \"需要获取您的位置信息以显示地图\",\n \"NSLocationAlwaysAndWhenInUseUsageDescription\": \"需要获取您的位置信息\"\n }\n }\n }\n}\n\n3️⃣ Android 配置(Config Plugin 会自动添加):\n使用 expo-gaode-map 的 Config Plugin 会自动添加必要的权限声明`,\n docUrl: `${this.docBaseUrl}/guide/getting-started.html#权限配置`,\n });\n }\n\n /**\n * 定位失败错误\n */\n static locationFailed(reason?: string): GaodeMapError {\n return new GaodeMapError({\n type: ErrorType.LOCATION_FAILED,\n message: `定位失败${reason ? `:${reason}` : ''}`,\n solution: `请检查以下问题:\n\n1️⃣ 设备 GPS 是否开启\n2️⃣ 网络连接是否正常\n3️⃣ 定位权限是否已授予\n4️⃣ 是否在室内或信号较弱的地方\n\n💡 解决方法:\n// 配置定位参数\nExpoGaodeMapModule.setLocationTimeout(30); // 增加超时时间\nExpoGaodeMapModule.setInterval(2000); // 设置定位间隔\n\n// Android 特有配置\nExpoGaodeMapModule.setLocationMode(2); // 高精度模式\nExpoGaodeMapModule.setGpsFirst(true); // GPS 优先\n\n// iOS 特有配置\nExpoGaodeMapModule.setDesiredAccuracy(0); // 最佳精度`,\n docUrl: `${this.docBaseUrl}/api/location.html`,\n });\n }\n\n /**\n * 原生模块不可用错误\n */\n static nativeModuleUnavailable(): GaodeMapError {\n return new GaodeMapError({\n type: ErrorType.NATIVE_MODULE_UNAVAILABLE,\n message: 'expo-gaode-map 原生模块不可用',\n solution: `请检查以下步骤:\n\n1️⃣ 确认已正确安装:\nnpm install expo-gaode-map\n# 或\npnpm install expo-gaode-map\n\n2️⃣ 重新构建原生代码:\nnpx expo prebuild --clean\nnpx expo run:android\nnpx expo run:ios\n\n3️⃣ 检查 Expo 版本兼容性:\n• expo-gaode-map 需要 Expo SDK 49+\n• 不支持 Expo Go,必须使用 Development Build\n\n4️⃣ 检查是否与其他包冲突:\n• 不能同时安装 expo-gaode-map 和 expo-gaode-map-navigation\n• 两个包选择其一使用\n\n5️⃣ 清理缓存后重试:\ncd android && ./gradlew clean && cd ..\ncd ios && pod deintegrate && pod install && cd ..`,\n docUrl: `${this.docBaseUrl}/guide/getting-started.html`,\n });\n }\n\n /**\n * 地图视图未初始化错误\n */\n static mapViewNotInitialized(methodName: string): GaodeMapError {\n return new GaodeMapError({\n type: ErrorType.MAP_VIEW_NOT_INITIALIZED,\n message: `无法调用 ${methodName}:地图视图尚未初始化`,\n solution: `请确保:\n\n1️⃣ MapView 已经渲染完成\n2️⃣ 使用 ref 获取地图实例后再调用方法\n\n正确用法:\nimport { MapView, MapViewRef } from 'expo-gaode-map';\n\nconst App = () => {\n const mapRef = useRef<MapViewRef>(null);\n \n // ❌ 错误:在渲染前调用\n // mapRef.current?.moveCamera(...);\n \n // ✅ 正确:等待地图加载完成\n const handleMapReady = () => {\n mapRef.current?.moveCamera({\n target: { latitude: 39.9, longitude: 116.4 },\n zoom: 15,\n });\n };\n \n return (\n <MapView\n ref={mapRef}\n onMapReady={handleMapReady}\n />\n );\n};`,\n docUrl: `${this.docBaseUrl}/api/mapview.html`,\n });\n }\n\n /**\n * 参数错误\n */\n static invalidParameter(paramName: string, expected: string, received: any): GaodeMapError {\n return new GaodeMapError({\n type: ErrorType.INVALID_PARAMETER,\n message: `参数 \"${paramName}\" 类型错误`,\n solution: `期望类型:${expected}\n实际接收:${typeof received} (${JSON.stringify(received)})\n\n请检查传入的参数是否符合要求。\n\n💡 提示:\n• 使用 TypeScript 可以在编译时发现类型错误\n• 参考 API 文档了解正确的参数类型`,\n docUrl: `${this.docBaseUrl}/api/`,\n });\n }\n\n /**\n * 网络错误\n */\n static networkError(originalError?: Error): GaodeMapError {\n return new GaodeMapError({\n type: ErrorType.NETWORK_ERROR,\n message: '网络请求失败',\n solution: `请检查:\n\n1️⃣ 网络连接是否正常\n2️⃣ API Key 是否有效\n3️⃣ 是否超出配额限制\n\n💡 如果问题持续,请:\n• 检查高德开放平台控制台\n• 查看 API 调用量和配额\n• 确认 Key 的服务是否已开通`,\n docUrl: `${this.docBaseUrl}/guide/troubleshooting.html`,\n originalError,\n });\n }\n\n /**\n * 包装原生错误,提供更友好的提示\n */\n static wrapNativeError(error: any, context: string): GaodeMapError {\n const errorMessage = error?.message || String(error);\n \n // SDK 未初始化相关错误\n if (\n errorMessage.includes('not initialized') ||\n errorMessage.includes('未初始化') ||\n errorMessage.includes('SDK未设置')\n ) {\n return this.sdkNotInitialized();\n }\n \n // API Key 相关错误\n if (\n errorMessage.includes('key') ||\n errorMessage.includes('invalid') ||\n errorMessage.includes('鉴权失败')\n ) {\n return this.invalidApiKey('both');\n }\n \n // 权限相关错误\n if (\n errorMessage.includes('permission') ||\n errorMessage.includes('权限')\n ) {\n return this.permissionDenied('location');\n }\n \n // 定位相关错误\n if (\n errorMessage.includes('location') ||\n errorMessage.includes('定位')\n ) {\n return this.locationFailed(errorMessage);\n }\n \n // 通用错误\n return new GaodeMapError({\n type: ErrorType.INVALID_PARAMETER,\n message: `${context} 失败`,\n solution: `原始错误信息:${errorMessage}\n\n如果问题持续,请:\n1. 查看完整的错误堆栈\n2. 检查 API 调用参数\n3. 提交 Issue:https://github.com/TomWq/expo-gaode-map/issues`,\n originalError: error instanceof Error ? error : undefined,\n });\n }\n}\n\n/**\n * 错误日志工具\n */\nexport class ErrorLogger {\n private static isEnabled = __DEV__;\n\n /**\n * 启用/禁用错误日志\n */\n static setEnabled(enabled: boolean) {\n this.isEnabled = enabled;\n }\n\n /**\n * 记录错误\n */\n static log(error: GaodeMapError) {\n if (!this.isEnabled) return;\n\n console.error(error.message);\n \n if (error.originalError) {\n console.error('原始错误:', error.originalError);\n }\n }\n\n /**\n * 记录警告\n */\n static warn(message: string, details?: any) {\n if (!this.isEnabled) return;\n \n console.warn(`⚠️ expo-gaode-map: ${message}`, details || '');\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"ErrorHandler.js","sourceRoot":"","sources":["../../src/utils/ErrorHandler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,CAAN,IAAY,SAiBX;AAjBD,WAAY,SAAS;IACnB,eAAe;IACf,wDAA2C,CAAA;IAC3C,mBAAmB;IACnB,gDAAmC,CAAA;IACnC,YAAY;IACZ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AC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IAE3E;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,OAAgB;QAChC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,GAAG,CAAC,KAAoB;QAC7B,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,OAAO;QAE5B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAE7B,IAAI,KAAK,CAAC,aAAa,EAAE,CAAC;YACxB,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,OAAe,EAAE,OAAa;QACxC,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,OAAO;QAE5B,OAAO,CAAC,IAAI,CAAC,uBAAuB,OAAO,EAAE,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;IAChE,CAAC","sourcesContent":["/**\n * 高德地图错误处理工具\n * 提供友好的错误提示和解决方案指引\n */\n\n/**\n * 错误类型枚举\n */\nexport enum ErrorType {\n /** SDK 未初始化 */\n SDK_NOT_INITIALIZED = 'SDK_NOT_INITIALIZED',\n /** API Key 配置错误 */\n INVALID_API_KEY = 'INVALID_API_KEY',\n /** 权限未授予 */\n PERMISSION_DENIED = 'PERMISSION_DENIED',\n /** 定位失败 */\n LOCATION_FAILED = 'LOCATION_FAILED',\n /** 原生模块不可用 */\n NATIVE_MODULE_UNAVAILABLE = 'NATIVE_MODULE_UNAVAILABLE',\n /** 地图视图未初始化 */\n MAP_VIEW_NOT_INITIALIZED = 'MAP_VIEW_NOT_INITIALIZED',\n /** 参数错误 */\n INVALID_PARAMETER = 'INVALID_PARAMETER',\n /** 网络错误 */\n NETWORK_ERROR = 'NETWORK_ERROR',\n}\n\n/**\n * 错误详情接口\n */\nexport interface ErrorDetails {\n /** 错误类型 */\n type: ErrorType;\n /** 错误消息 */\n message: string;\n /** 解决方案 */\n solution: string;\n /** 文档链接 */\n docUrl?: string;\n /** 原始错误 */\n originalError?: Error;\n}\n\n/**\n * 自定义错误类\n */\nexport class GaodeMapError extends Error {\n type: ErrorType;\n solution: string;\n docUrl?: string;\n originalError?: Error;\n\n constructor(details: ErrorDetails) {\n const fullMessage = `\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n🗺️ 高德地图错误 [${details.type}]\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n❌ 错误信息:\n ${details.message}\n\n💡 解决方案:\n ${details.solution}\n\n${details.docUrl ? `📖 详细文档:\\n ${details.docUrl}\\n` : ''}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n`;\n super(fullMessage);\n this.name = 'GaodeMapError';\n this.type = details.type;\n this.solution = details.solution;\n this.docUrl = details.docUrl;\n this.originalError = details.originalError;\n }\n}\n\n/**\n * 错误处理器类\n */\nexport class ErrorHandler {\n private static docBaseUrl = 'https://TomWq.github.io/expo-gaode-map';\n\n /**\n * SDK 未初始化错误\n */\n static sdkNotInitialized(): GaodeMapError {\n return new GaodeMapError({\n type: ErrorType.SDK_NOT_INITIALIZED,\n message: '高德地图 SDK 尚未初始化',\n solution: `请在使用地图功能前先调用 initSDK():\n\nimport ExpoGaodeMapModule from 'expo-gaode-map';\n\nuseEffect(() => {\n // 在组件挂载时初始化\n ExpoGaodeMapModule.initSDK({\n androidKey: 'your-android-key',\n iosKey: 'your-ios-key',\n });\n}, []);\n\n⚠️ 常见原因:\n1. 忘记调用 initSDK() 就使用了定位或地图功能\n2. initSDK() 调用时机过晚(应在 useEffect 中尽早调用)\n3. 使用 Config Plugin 但未重新构建原生代码`,\n docUrl: `${this.docBaseUrl}/guide/initialization.html`,\n });\n }\n\n /**\n * API Key 配置错误\n */\n static invalidApiKey(platform: 'android' | 'ios' | 'both'): GaodeMapError {\n const platformText = {\n android: 'Android',\n ios: 'iOS',\n both: 'Android 和 iOS',\n }[platform];\n\n return new GaodeMapError({\n type: ErrorType.INVALID_API_KEY,\n message: `${platformText} API Key 配置错误或未配置`,\n solution: `⚠️ API Key 与 Bundle ID 不匹配是最常见的原因!\n\n请检查以下步骤:\n\n1️⃣ 确认 API Key 的配置:\n • 访问高德开放平台:https://lbs.amap.com/\n • 检查您的应用配置中的 Bundle ID 是否与当前项目一致\n • iOS Bundle ID:在 Xcode → Target → General → Bundle Identifier 查看\n • Android 包名:在 android/app/build.gradle → applicationId 查看\n\n2️⃣ 重新创建正确的 API Key(如果 Bundle ID 不同):\n • 在高德开放平台创建新应用\n • 填写正确的 Bundle ID(iOS)或包名(Android)\n • 获取新的 API Key\n\n3️⃣ 配置 API Key(推荐使用 Config Plugin):\n\n在 app.json 中配置:\n{\n \"expo\": {\n \"plugins\": [\n [\n \"expo-gaode-map\",\n {\n \"androidKey\": \"your-android-key\",\n \"iosKey\": \"your-ios-key\"\n }\n ]\n ]\n }\n}\n\n然后重新构建:\nnpx expo prebuild --clean\nnpx expo run:${platform === 'ios' ? 'ios' : 'android'}\n\n4️⃣ 或在代码中配置:\nExpoGaodeMapModule.initSDK({\n androidKey: 'your-android-key',\n iosKey: 'your-ios-key',\n});`,\n docUrl: `${this.docBaseUrl}/guide/initialization.html`,\n });\n }\n\n /**\n * 权限未授予错误\n */\n static permissionDenied(permissionType: 'location'): GaodeMapError {\n return new GaodeMapError({\n type: ErrorType.PERMISSION_DENIED,\n message: '定位权限未授予,无法使用定位功能',\n solution: `请按以下步骤授予权限:\n\n1️⃣ 请求权限:\nimport ExpoGaodeMapModule from 'expo-gaode-map';\n\nconst checkPermission = async () => {\n // 检查权限状态\n const status = await ExpoGaodeMapModule.checkLocationPermission();\n \n if (!status.granted) {\n // 请求权限\n const result = await ExpoGaodeMapModule.requestLocationPermission();\n \n if (!result.granted) {\n // 用户拒绝授权,引导用户去设置\n Alert.alert(\n '需要定位权限',\n '请在设置中开启定位权限以使用地图功能',\n [\n { text: '取消', style: 'cancel' },\n { text: '去设置', onPress: () => Linking.openSettings() }\n ]\n );\n }\n }\n};\n\n2️⃣ iOS 配置(在 app.json 中):\n{\n \"expo\": {\n \"ios\": {\n \"infoPlist\": {\n \"NSLocationWhenInUseUsageDescription\": \"需要获取您的位置信息以显示地图\",\n \"NSLocationAlwaysAndWhenInUseUsageDescription\": \"需要获取您的位置信息\"\n }\n }\n }\n}\n\n3️⃣ Android 配置(Config Plugin 会自动添加):\n使用 expo-gaode-map 的 Config Plugin 会自动添加必要的权限声明`,\n docUrl: `${this.docBaseUrl}/guide/getting-started.html#权限配置`,\n });\n }\n\n /**\n * 定位失败错误\n */\n static locationFailed(reason?: string): GaodeMapError {\n return new GaodeMapError({\n type: ErrorType.LOCATION_FAILED,\n message: `定位失败${reason ? `:${reason}` : ''}`,\n solution: `⚠️ 最常见原因:API Key 与 Bundle ID 不匹配!\n\n请按以下顺序排查:\n\n1️⃣ 检查 API Key 配置(最常见问题):\n • 访问高德开放平台:https://lbs.amap.com/\n • 确认您的应用的 Bundle ID 与当前项目一致\n • iOS Bundle ID:在 Xcode → Target → General → Bundle Identifier\n • Android 包名:在 android/app/build.gradle → applicationId\n \n 如果 Bundle ID 不同,必须在高德平台重新创建应用并获取新 Key\n\n2️⃣ 检查设备 GPS 和网络:\n • 确认设备 GPS 已开启\n • 检查网络连接是否正常\n • 尝试在室外空旷处测试\n\n3️⃣ 检查定位权限:\n • iOS:设置 → 隐私 → 定位服务 → 允许应用访问\n • Android:设置 → 应用 → 权限管理 → 位置信息\n\n4️⃣ 配置定位参数(如果 API Key 正确但定位仍失败):\nExpoGaodeMapModule.setLocationTimeout(30); // 增加超时时间\nExpoGaodeMapModule.setInterval(2000); // 设置定位间隔\n\n// Android 特有配置\nExpoGaodeMapModule.setLocationMode(2); // 高精度模式\nExpoGaodeMapModule.setGpsFirst(true); // GPS 优先\n\n// iOS 特有配置\nExpoGaodeMapModule.setDesiredAccuracy(0); // 最佳精度`,\n docUrl: `${this.docBaseUrl}/api/location.html`,\n });\n }\n\n /**\n * 原生模块不可用错误\n */\n static nativeModuleUnavailable(): GaodeMapError {\n return new GaodeMapError({\n type: ErrorType.NATIVE_MODULE_UNAVAILABLE,\n message: 'expo-gaode-map 原生模块不可用',\n solution: `请检查以下步骤:\n\n1️⃣ 确认已正确安装:\nnpm install expo-gaode-map\n# 或\nbun install expo-gaode-map\n\n2️⃣ 重新构建原生代码:\nnpx expo prebuild --clean\nnpx expo run:android\nnpx expo run:ios\n\n3️⃣ 检查 Expo 版本兼容性:\n• expo-gaode-map 需要 Expo SDK 49+\n• 不支持 Expo Go,必须使用 Development Build\n\n4️⃣ 检查是否与其他包冲突:\n• 不能同时安装 expo-gaode-map 和 expo-gaode-map-navigation\n• 两个包选择其一使用\n\n5️⃣ 清理缓存后重试:\ncd android && ./gradlew clean && cd ..\ncd ios && pod deintegrate && pod install && cd ..`,\n docUrl: `${this.docBaseUrl}/guide/getting-started.html`,\n });\n }\n\n /**\n * 地图视图未初始化错误\n */\n static mapViewNotInitialized(methodName: string): GaodeMapError {\n return new GaodeMapError({\n type: ErrorType.MAP_VIEW_NOT_INITIALIZED,\n message: `无法调用 ${methodName}:地图视图尚未初始化`,\n solution: `请确保:\n\n1️⃣ MapView 已经渲染完成\n2️⃣ 使用 ref 获取地图实例后再调用方法\n\n正确用法:\nimport { MapView, MapViewRef } from 'expo-gaode-map';\n\nconst App = () => {\n const mapRef = useRef<MapViewRef>(null);\n \n // ❌ 错误:在渲染前调用\n // mapRef.current?.moveCamera(...);\n \n // ✅ 正确:等待地图加载完成\n const handleMapReady = () => {\n mapRef.current?.moveCamera({\n target: { latitude: 39.9, longitude: 116.4 },\n zoom: 15,\n });\n };\n \n return (\n <MapView\n ref={mapRef}\n onMapReady={handleMapReady}\n />\n );\n};`,\n docUrl: `${this.docBaseUrl}/api/mapview.html`,\n });\n }\n\n /**\n * 参数错误\n */\n static invalidParameter(paramName: string, expected: string, received: any): GaodeMapError {\n return new GaodeMapError({\n type: ErrorType.INVALID_PARAMETER,\n message: `参数 \"${paramName}\" 类型错误`,\n solution: `期望类型:${expected}\n实际接收:${typeof received} (${JSON.stringify(received)})\n\n请检查传入的参数是否符合要求。\n\n💡 提示:\n• 使用 TypeScript 可以在编译时发现类型错误\n• 参考 API 文档了解正确的参数类型`,\n docUrl: `${this.docBaseUrl}/api/`,\n });\n }\n\n /**\n * 网络错误\n */\n static networkError(originalError?: Error): GaodeMapError {\n return new GaodeMapError({\n type: ErrorType.NETWORK_ERROR,\n message: '网络请求失败',\n solution: `请检查:\n\n1️⃣ 网络连接是否正常\n2️⃣ API Key 是否有效\n3️⃣ 是否超出配额限制\n\n💡 如果问题持续,请:\n• 检查高德开放平台控制台\n• 查看 API 调用量和配额\n• 确认 Key 的服务是否已开通`,\n docUrl: `${this.docBaseUrl}/guide/troubleshooting.html`,\n originalError,\n });\n }\n\n /**\n * 包装原生错误,提供更友好的提示\n */\n static wrapNativeError(error: any, context: string): GaodeMapError {\n const errorMessage = error?.message || String(error);\n \n // SDK 未初始化相关错误\n if (\n errorMessage.includes('not initialized') ||\n errorMessage.includes('未初始化') ||\n errorMessage.includes('SDK未设置')\n ) {\n return this.sdkNotInitialized();\n }\n \n // API Key 相关错误\n if (\n errorMessage.includes('key') ||\n errorMessage.includes('invalid') ||\n errorMessage.includes('鉴权失败')\n ) {\n return this.invalidApiKey('both');\n }\n \n // 权限相关错误\n if (\n errorMessage.includes('permission') ||\n errorMessage.includes('权限')\n ) {\n return this.permissionDenied('location');\n }\n \n // 定位相关错误\n if (\n errorMessage.includes('location') ||\n errorMessage.includes('定位')\n ) {\n return this.locationFailed(errorMessage);\n }\n \n // 通用错误\n return new GaodeMapError({\n type: ErrorType.INVALID_PARAMETER,\n message: `${context} 失败`,\n solution: `原始错误信息:${errorMessage}\n\n如果问题持续,请:\n1. 查看完整的错误堆栈\n2. 检查 API 调用参数\n3. 提交 Issue:https://github.com/TomWq/expo-gaode-map/issues`,\n originalError: error instanceof Error ? error : undefined,\n });\n }\n}\n\n/**\n * 错误日志工具\n */\nexport class ErrorLogger {\n // 兼容不同环境:Bun/Jest/Node\n private static isEnabled = typeof __DEV__ !== 'undefined' ? __DEV__ : true;\n\n /**\n * 启用/禁用错误日志\n */\n static setEnabled(enabled: boolean) {\n this.isEnabled = enabled;\n }\n\n /**\n * 记录错误\n */\n static log(error: GaodeMapError) {\n if (!this.isEnabled) return;\n\n console.error(error.message);\n \n if (error.originalError) {\n console.error('原始错误:', error.originalError);\n }\n }\n\n /**\n * 记录警告\n */\n static warn(message: string, details?: any) {\n if (!this.isEnabled) return;\n \n console.warn(`⚠️ expo-gaode-map: ${message}`, details || '');\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-gaode-map",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.12",
|
|
4
4
|
"description": "一个功能完整的高德地图 React Native 组件库,基于 Expo Modules 开发,提供地图显示、定位、覆盖物等功能。",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -12,8 +12,19 @@
|
|
|
12
12
|
"expo-module.config.json",
|
|
13
13
|
"plugin/build"
|
|
14
14
|
],
|
|
15
|
-
"
|
|
16
|
-
"
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "expo-module build && bun run build:plugin",
|
|
17
|
+
"build:plugin": "tsc --project plugin/tsconfig.json",
|
|
18
|
+
"clean": "expo-module clean && rm -rf plugin/build",
|
|
19
|
+
"lint": "expo-module lint",
|
|
20
|
+
"test": "expo-module test",
|
|
21
|
+
"prepare": "expo-module prepare && bun run build:plugin",
|
|
22
|
+
"prepublishOnly": "expo-module prepublishOnly",
|
|
23
|
+
"expo-module": "expo-module",
|
|
24
|
+
"open:ios": "xed example/ios",
|
|
25
|
+
"open:android": "open -a \"Android Studio\" example/android",
|
|
26
|
+
"publish:next": "bun publish --tag next",
|
|
27
|
+
"publish:latest": "bun publish --tag latest"
|
|
17
28
|
},
|
|
18
29
|
"keywords": [
|
|
19
30
|
"react-native",
|
|
@@ -54,17 +65,5 @@
|
|
|
54
65
|
"expo": "*",
|
|
55
66
|
"react": "*",
|
|
56
67
|
"react-native": "*"
|
|
57
|
-
},
|
|
58
|
-
"scripts": {
|
|
59
|
-
"build": "expo-module build && pnpm run build:plugin",
|
|
60
|
-
"build:plugin": "tsc --project plugin/tsconfig.json",
|
|
61
|
-
"clean": "expo-module clean && rm -rf plugin/build",
|
|
62
|
-
"lint": "expo-module lint",
|
|
63
|
-
"test": "expo-module test",
|
|
64
|
-
"expo-module": "expo-module",
|
|
65
|
-
"open:ios": "xed example/ios",
|
|
66
|
-
"open:android": "open -a \"Android Studio\" example/android",
|
|
67
|
-
"publish:next": "pnpm publish --tag next",
|
|
68
|
-
"publish:latest": "pnpm publish --tag latest"
|
|
69
68
|
}
|
|
70
|
-
}
|
|
69
|
+
}
|
|
@@ -1,8 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const config_plugins_1 = require("@expo/config-plugins");
|
|
4
|
+
const pkg = require('expo-gaode-map/package.json');
|
|
5
|
+
/** 默认定位权限描述 */
|
|
6
|
+
const DEFAULT_LOCATION_USAGE = '需要访问您的位置信息以提供地图服务';
|
|
4
7
|
/**
|
|
5
|
-
* iOS:
|
|
8
|
+
* iOS: 使用 IOSConfig 添加定位权限
|
|
9
|
+
*/
|
|
10
|
+
const withGaodeMapIOSPermissions = (config, props) => {
|
|
11
|
+
if (props.enableLocation === false) {
|
|
12
|
+
return config;
|
|
13
|
+
}
|
|
14
|
+
const description = props.locationDescription || DEFAULT_LOCATION_USAGE;
|
|
15
|
+
// 构建权限配置对象
|
|
16
|
+
const permissionDefaults = {
|
|
17
|
+
NSLocationWhenInUseUsageDescription: DEFAULT_LOCATION_USAGE,
|
|
18
|
+
};
|
|
19
|
+
const permissionValues = {
|
|
20
|
+
NSLocationWhenInUseUsageDescription: description,
|
|
21
|
+
};
|
|
22
|
+
// 如果启用后台定位,添加额外权限
|
|
23
|
+
if (props.enableBackgroundLocation) {
|
|
24
|
+
permissionDefaults.NSLocationAlwaysUsageDescription = DEFAULT_LOCATION_USAGE;
|
|
25
|
+
permissionDefaults.NSLocationAlwaysAndWhenInUseUsageDescription = DEFAULT_LOCATION_USAGE;
|
|
26
|
+
permissionValues.NSLocationAlwaysUsageDescription = description;
|
|
27
|
+
permissionValues.NSLocationAlwaysAndWhenInUseUsageDescription = description;
|
|
28
|
+
}
|
|
29
|
+
// 使用 IOSConfig.Permissions 简化权限配置
|
|
30
|
+
return config_plugins_1.IOSConfig.Permissions.createPermissionsPlugin(permissionDefaults)(config, permissionValues);
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* iOS: 修改 Info.plist 添加 API Key 和后台模式
|
|
6
34
|
*/
|
|
7
35
|
const withGaodeMapInfoPlist = (config, props) => {
|
|
8
36
|
return (0, config_plugins_1.withInfoPlist)(config, (config) => {
|
|
@@ -10,20 +38,14 @@ const withGaodeMapInfoPlist = (config, props) => {
|
|
|
10
38
|
if (props.iosApiKey) {
|
|
11
39
|
config.modResults.AMapApiKey = props.iosApiKey;
|
|
12
40
|
}
|
|
13
|
-
//
|
|
14
|
-
if (props.
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
config.modResults.NSLocationAlwaysAndWhenInUseUsageDescription = description;
|
|
22
|
-
// 添加后台定位模式
|
|
23
|
-
if (!config.modResults.UIBackgroundModes) {
|
|
24
|
-
config.modResults.UIBackgroundModes = [];
|
|
25
|
-
}
|
|
26
|
-
if (!config.modResults.UIBackgroundModes.includes('location')) {
|
|
41
|
+
// 添加后台定位模式(如果启用)
|
|
42
|
+
if (props.enableBackgroundLocation) {
|
|
43
|
+
const modes = config.modResults.UIBackgroundModes;
|
|
44
|
+
if (!modes) {
|
|
45
|
+
config.modResults.UIBackgroundModes = ['location'];
|
|
46
|
+
}
|
|
47
|
+
else if (Array.isArray(modes)) {
|
|
48
|
+
if (modes.indexOf('location') === -1) {
|
|
27
49
|
config.modResults.UIBackgroundModes.push('location');
|
|
28
50
|
}
|
|
29
51
|
}
|
|
@@ -41,55 +63,29 @@ const withGaodeMapInfoPlist = (config, props) => {
|
|
|
41
63
|
* 2. 通过 JavaScript 调用 ExpoGaodeMap.initSDK({ iosKey: 'your-key' })
|
|
42
64
|
*/
|
|
43
65
|
/**
|
|
44
|
-
* Android:
|
|
66
|
+
* Android: 使用 AndroidConfig 添加基础权限
|
|
67
|
+
*/
|
|
68
|
+
const withGaodeMapAndroidPermissions = (config, props) => {
|
|
69
|
+
// 基础定位权限(高德地图 SDK 必需)
|
|
70
|
+
const basePermissions = [
|
|
71
|
+
'android.permission.ACCESS_COARSE_LOCATION',
|
|
72
|
+
'android.permission.ACCESS_FINE_LOCATION',
|
|
73
|
+
'android.permission.ACCESS_NETWORK_STATE',
|
|
74
|
+
'android.permission.ACCESS_WIFI_STATE',
|
|
75
|
+
];
|
|
76
|
+
// 后台定位权限(可选)
|
|
77
|
+
if (props.enableBackgroundLocation) {
|
|
78
|
+
basePermissions.push('android.permission.ACCESS_BACKGROUND_LOCATION', 'android.permission.FOREGROUND_SERVICE', 'android.permission.FOREGROUND_SERVICE_LOCATION');
|
|
79
|
+
}
|
|
80
|
+
// 使用 AndroidConfig.Permissions 简化权限配置(自动去重)
|
|
81
|
+
return config_plugins_1.AndroidConfig.Permissions.withPermissions(config, basePermissions);
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Android: 修改 AndroidManifest.xml 添加 API Key 和服务
|
|
45
85
|
*/
|
|
46
86
|
const withGaodeMapAndroidManifest = (config, props) => {
|
|
47
87
|
return (0, config_plugins_1.withAndroidManifest)(config, (config) => {
|
|
48
88
|
const androidManifest = config.modResults.manifest;
|
|
49
|
-
// 基础权限(库中已包含,这里不重复添加)
|
|
50
|
-
// INTERNET, ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE
|
|
51
|
-
// ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION
|
|
52
|
-
// 添加基础权限(高德地图 SDK 必需)
|
|
53
|
-
const basePermissions = [
|
|
54
|
-
'android.permission.ACCESS_COARSE_LOCATION',
|
|
55
|
-
'android.permission.ACCESS_FINE_LOCATION',
|
|
56
|
-
'android.permission.ACCESS_NETWORK_STATE',
|
|
57
|
-
'android.permission.ACCESS_WIFI_STATE',
|
|
58
|
-
'android.permission.WRITE_EXTERNAL_STORAGE',
|
|
59
|
-
'android.permission.READ_PHONE_STATE',
|
|
60
|
-
'android.permission.BLUETOOTH',
|
|
61
|
-
'android.permission.BLUETOOTH_ADMIN',
|
|
62
|
-
];
|
|
63
|
-
if (!androidManifest['uses-permission']) {
|
|
64
|
-
androidManifest['uses-permission'] = [];
|
|
65
|
-
}
|
|
66
|
-
basePermissions.forEach((permission) => {
|
|
67
|
-
const hasPermission = androidManifest['uses-permission']?.some((item) => item.$?.['android:name'] === permission);
|
|
68
|
-
if (!hasPermission) {
|
|
69
|
-
androidManifest['uses-permission']?.push({
|
|
70
|
-
$: { 'android:name': permission },
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
// 后台定位权限(可选)
|
|
75
|
-
if (props.enableBackgroundLocation) {
|
|
76
|
-
const backgroundPermissions = [
|
|
77
|
-
'android.permission.ACCESS_BACKGROUND_LOCATION',
|
|
78
|
-
'android.permission.FOREGROUND_SERVICE',
|
|
79
|
-
'android.permission.FOREGROUND_SERVICE_LOCATION',
|
|
80
|
-
];
|
|
81
|
-
if (!androidManifest['uses-permission']) {
|
|
82
|
-
androidManifest['uses-permission'] = [];
|
|
83
|
-
}
|
|
84
|
-
backgroundPermissions.forEach((permission) => {
|
|
85
|
-
const hasPermission = androidManifest['uses-permission']?.some((item) => item.$?.['android:name'] === permission);
|
|
86
|
-
if (!hasPermission) {
|
|
87
|
-
androidManifest['uses-permission']?.push({
|
|
88
|
-
$: { 'android:name': permission },
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
89
|
// 添加高德定位服务(APSService)- 必需
|
|
94
90
|
const mainApplication = androidManifest.application?.[0];
|
|
95
91
|
if (mainApplication) {
|
|
@@ -168,12 +164,11 @@ const withGaodeMap = (config, props = {}) => {
|
|
|
168
164
|
config_plugins_1.WarningAggregator.addWarningIOS('expo-gaode-map', '未配置 API Key。请在 app.json 的 plugins 中配置 iosApiKey 和 androidApiKey');
|
|
169
165
|
}
|
|
170
166
|
// 应用 iOS 配置
|
|
171
|
-
config =
|
|
172
|
-
//
|
|
173
|
-
// 1. SDK 会自动从 Info.plist 读取 AMapApiKey
|
|
174
|
-
// 2. 可以通过 ExpoGaodeMapModule.initSDK() 方法初始化
|
|
167
|
+
config = withGaodeMapIOSPermissions(config, props); // 使用 IOSConfig 添加权限
|
|
168
|
+
config = withGaodeMapInfoPlist(config, props); // 添加 API Key 和后台模式
|
|
175
169
|
// 应用 Android 配置
|
|
176
|
-
config =
|
|
170
|
+
config = withGaodeMapAndroidPermissions(config, props); // 使用 AndroidConfig 添加权限
|
|
171
|
+
config = withGaodeMapAndroidManifest(config, props); // 添加服务和 API Key
|
|
177
172
|
config = withGaodeMapAppBuildGradle(config, props);
|
|
178
173
|
return config;
|
|
179
174
|
};
|
|
@@ -181,4 +176,4 @@ const withGaodeMap = (config, props = {}) => {
|
|
|
181
176
|
* 导出为可运行一次的插件
|
|
182
177
|
* 这确保插件只会运行一次,即使在配置中被多次引用
|
|
183
178
|
*/
|
|
184
|
-
exports.default = (0, config_plugins_1.createRunOncePlugin)(withGaodeMap,
|
|
179
|
+
exports.default = (0, config_plugins_1.createRunOncePlugin)(withGaodeMap, pkg.name, pkg.version);
|