expo-gaode-map 2.0.0 → 2.1.0-beta.0

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/.eslintrc.js CHANGED
@@ -1,5 +1,2 @@
1
- module.exports = {
2
- root: true,
3
- extends: ['universe/native', 'universe/web'],
4
- ignorePatterns: ['build'],
5
- };
1
+ // @generated by expo-module-scripts
2
+ module.exports = require('expo-module-scripts/eslintrc.base.js');
package/README.md CHANGED
@@ -1,136 +1,35 @@
1
1
  # expo-gaode-map
2
2
 
3
- [English](./README.en.md) | 简体中文
3
+ 一个功能完整的高德地图 React Native 组件库,基于 Expo Modules 开发,提供地图显示、定位、覆盖物等功能。
4
4
 
5
- 一个功能完整的高德地图 React Native 组件库,**基于 Expo Modules 开发**,提供地图显示、定位、覆盖物等功能。
5
+ # API documentation
6
6
 
7
- > 💡 本组件使用 [Expo Modules API](https://docs.expo.dev/modules/overview/) 构建,提供了类型安全的原生模块接口和优秀的开发体验。
7
+ - [Documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/gaode-map/)
8
+ - [Documentation for the main branch](https://docs.expo.dev/versions/unversioned/sdk/gaode-map/)
8
9
 
9
- ## 📖 完整文档
10
+ # Installation in managed Expo projects
10
11
 
11
- **👉 [在线文档网站](https://TomWq.github.io/expo-gaode-map/)** - 包含完整的 API 文档、使用指南和示例代码
12
+ For [managed](https://docs.expo.dev/archive/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](#api-documentation). If you follow the link and there is no documentation available then this library is not yet usable within managed projects — it is likely to be included in an upcoming Expo SDK release.
12
13
 
13
- ## 主要特性
14
+ # Installation in bare React Native projects
14
15
 
15
- - 完整的地图功能(多种地图类型、手势控制、相机操作)
16
- - ✅ 精准定位(连续定位、单次定位、坐标转换)
17
- - ✅ 丰富的覆盖物(Circle、Marker、Polyline、Polygon、HeatMap、Cluster 等)
18
- - ✅ 完整的 TypeScript 类型定义
19
- - ✅ 跨平台支持(Android、iOS)
20
- - ✅ 同时支持 React Native 新旧架构(Paper & Fabric)
16
+ For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
21
17
 
22
- ## 📦 安装
18
+ ### Add the package to your npm dependencies
23
19
 
24
- ### 稳定版本(推荐)
25
-
26
- ```bash
27
- npm install expo-gaode-map
28
- # 或
29
- yarn add expo-gaode-map
30
- # 或
31
- pnpm add expo-gaode-map
32
20
  ```
33
-
34
- ## 🚀 快速开始
35
-
36
- ### 1. 获取高德地图 API Key
37
-
38
- 前往 [高德开放平台](https://lbs.amap.com/) 注册并创建应用,获取 API Key。
39
-
40
- > ⚠️ **重要提示**: 高德地图 SDK 需要在原生项目中进行配置(API Key、权限、隐私合规等)
41
- >
42
- > 详细配置请查看:[初始化指南](https://TomWq.github.io/expo-gaode-map/guide/initialization.html)
43
-
44
- ### 2. 基础使用
45
-
46
- ```tsx
47
- import { useEffect, useState } from 'react';
48
- import { MapView, ExpoGaodeMapModule } from 'expo-gaode-map';
49
-
50
- export default function App() {
51
- const [initialPosition, setInitialPosition] = useState(null);
52
-
53
- useEffect(() => {
54
- const initialize = async () => {
55
- // 1. 初始化 SDK
56
- ExpoGaodeMapModule.initSDK({
57
- androidKey: 'your-android-api-key',
58
- iosKey: 'your-ios-api-key',
59
- });
60
-
61
- // 2. 检查并请求权限
62
- const status = await ExpoGaodeMapModule.checkLocationPermission();
63
- if (!status.granted) {
64
- await ExpoGaodeMapModule.requestLocationPermission();
65
- }
66
-
67
- // 3. 获取位置并设置地图
68
- try {
69
- const location = await ExpoGaodeMapModule.getCurrentLocation();
70
- setInitialPosition({
71
- target: { latitude: location.latitude, longitude: location.longitude },
72
- zoom: 15
73
- });
74
- } catch (error) {
75
- // 使用默认位置
76
- setInitialPosition({
77
- target: { latitude: 39.9, longitude: 116.4 },
78
- zoom: 10
79
- });
80
- }
81
- };
82
-
83
- initialize();
84
- }, []);
85
-
86
- if (!initialPosition) return null;
87
-
88
- return (
89
- <MapView
90
- style={{ flex: 1 }}
91
- initialCameraPosition={initialPosition}
92
- myLocationEnabled={true}
93
- />
94
- );
95
- }
21
+ npm install expo-gaode-map
96
22
  ```
97
23
 
98
- ## 📚 文档导航
99
-
100
- - [快速开始](https://TomWq.github.io/expo-gaode-map/guide/getting-started.html) - 快速上手指南
101
- - [初始化指南](https://TomWq.github.io/expo-gaode-map/guide/initialization.html) - SDK 初始化和权限配置
102
- - [API 文档](https://TomWq.github.io/expo-gaode-map/api/) - 完整的 API 参考
103
- - [使用示例](https://TomWq.github.io/expo-gaode-map/examples/) - 详细的代码示例
104
- - [架构文档](https://TomWq.github.io/expo-gaode-map/guide/architecture.html) - 项目结构说明
105
-
106
- ## 🤝 贡献
107
-
108
- 欢迎提交 Issue 和 Pull Request!
109
-
110
- ## 📄 许可证
111
-
112
- MIT
113
-
114
- ## 🔗 相关链接
115
-
116
- - [在线文档](https://TomWq.github.io/expo-gaode-map/)
117
- - [GitHub 仓库](https://github.com/TomWq/expo-gaode-map)
118
- - [高德地图开放平台](https://lbs.amap.com/)
119
- - [Expo Modules API](https://docs.expo.dev/modules/overview/)
24
+ ### Configure for Android
120
25
 
121
- ## 🙏 致谢
122
26
 
123
- 本项目在开发过程中参考了以下优秀项目:
124
27
 
125
- - **[react-native-amap3d](https://github.com/qiuxiang/react-native-amap3d)** - 一个优秀的 React Native 高德地图组件
126
28
 
127
- 感谢这些开源项目的贡献者们!
29
+ ### Configure for iOS
128
30
 
129
- ## 📮 反馈与支持
31
+ Run `npx pod-install` after installing the npm package.
130
32
 
131
- 如果你在使用过程中遇到问题或有任何建议,欢迎:
33
+ # Contributing
132
34
 
133
- - 📝 提交 [GitHub Issue](https://github.com/TomWq/expo-gaode-map/issues)
134
- - 💬 参与 [Discussions](https://github.com/TomWq/expo-gaode-map/discussions)
135
- - ⭐ 给项目点个 Star 支持一下
136
- - 💬 加入 QQ 群:952241387
35
+ Contributions are very welcome! Please refer to guidelines described in the [contributing guide]( https://github.com/expo/expo#contributing).
@@ -43,6 +43,7 @@ android {
43
43
  }
44
44
 
45
45
  dependencies {
46
- // 3D地图SDK(已包含定位功能)
46
+
47
47
  implementation 'com.amap.api:3dmap:10.0.600'
48
+
48
49
  }
@@ -1,52 +1,23 @@
1
1
  <?xml version="1.0" encoding="utf-8"?>
2
2
  <manifest xmlns:android="http://schemas.android.com/apk/res/android">
3
3
 
4
- <!-- 高德地图必需权限 -->
5
- <!-- 用于访问网络 -->
4
+ <!-- 网络权限 (必需) -->
6
5
  <uses-permission android:name="android.permission.INTERNET" />
7
- <!-- 用于获取网络状态 -->
8
6
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
9
- <!-- 用于访问wifi网络信息 -->
10
7
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
11
- <!-- 用于获取wifi的获取权限 -->
12
- <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
13
8
 
14
- <!-- 定位相关权限 -->
15
- <!-- 用于访问GPS定位 -->
9
+ <!-- 基础定位权限 (必需) -->
16
10
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
17
11
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
18
- <!-- 用于获取运营商信息,用于支持提供运营商信息相关的接口 -->
19
- <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
20
-
21
- <!-- Android 10及以上需要后台定位权限 -->
22
- <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
23
-
24
- <!-- 前台服务权限 (Android 9+) -->
25
- <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
26
- <!-- Android 14+ 需要指定前台服务类型 -->
27
- <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
28
-
29
- <!-- 写入扩展存储,用于缓存地图数据 -->
30
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
31
- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
32
-
33
- <!-- 用于读取手机当前的状态 -->
34
- <uses-permission android:name="android.permission.READ_PHONE_STATE" />
35
12
 
36
13
  <application>
37
- <!-- 高德地图 API Key(这里只是示例,实际会通过代码设置) -->
38
- <!--
39
- <meta-data
40
- android:name="com.amap.api.v2.apikey"
41
- android:value="YOUR_API_KEY_HERE"/>
42
- -->
43
-
44
- <!-- 定位前台服务 -->
14
+
15
+ <!-- 高德地图定位服务 (必需) -->
45
16
  <service
46
- android:name="expo.modules.gaodemap.services.LocationForegroundService"
17
+ android:name="com.amap.api.location.APSService"
47
18
  android:enabled="true"
48
- android:exported="false"
49
- android:foregroundServiceType="location" />
19
+ android:exported="false" />
20
+
50
21
  </application>
51
22
 
52
23
  </manifest>
@@ -396,16 +396,28 @@ class ExpoGaodeMapView(context: Context, appContext: AppContext) : ExpoView(cont
396
396
  /** 销毁地图 */
397
397
  @Suppress("unused")
398
398
  fun onDestroy() {
399
- // 清理 Handler 回调,防止内存泄露
400
- mainHandler.removeCallbacksAndMessages(null)
401
-
402
- // 清理地图监听器
403
- aMap.setOnMapClickListener(null)
404
- aMap.setOnMapLongClickListener(null)
405
- aMap.setOnMapLoadedListener(null)
399
+ try {
400
+ // 清理 Handler 回调,防止内存泄露
401
+ mainHandler.removeCallbacksAndMessages(null)
402
+
403
+ // 清理所有地图监听器
404
+ aMap.setOnMapClickListener(null)
405
+ aMap.setOnMapLongClickListener(null)
406
+ aMap.setOnMapLoadedListener(null)
407
+ aMap.setOnCameraChangeListener(null)
408
+ aMap.setOnMarkerClickListener(null)
409
+ aMap.setOnMarkerDragListener(null)
410
+
411
+ // 清除所有覆盖物
412
+ aMap.clear()
413
+
414
+ // 销毁地图实例
415
+ mapView.onDestroy()
416
+ } catch (e: Exception) {
417
+ // 静默处理异常,确保销毁流程不会中断
418
+ android.util.Log.e("ExpoGaodeMapView", "Error destroying map", e)
419
+ }
406
420
 
407
- // 销毁地图
408
- mapView.onDestroy()
409
421
  }
410
422
 
411
423
  /** 保存实例状态 */
@@ -14,9 +14,13 @@ class ExpoGaodeMapViewModule : Module() {
14
14
  Events("onMapPress", "onMapLongPress", "onLoad", "onLocation", "onCameraMove", "onCameraIdle")
15
15
 
16
16
  // ✅ 关键修复:拦截 React Native 的视图操作异常
17
- OnViewDestroys { _: ExpoGaodeMapView ->
17
+
18
+ OnViewDestroys { view: ExpoGaodeMapView ->
19
+ // 销毁地图实例,释放资源
20
+ view.onDestroy()
18
21
  }
19
22
 
23
+
20
24
  Prop<Int>("mapType") { view, type ->
21
25
  view.mapType = type
22
26
  view.setMapType(type)
package/build/index.d.ts CHANGED
@@ -5,5 +5,6 @@ export type { SDKConfig, PermissionStatus } from './ExpoGaodeMapModule';
5
5
  export { default as MapView } from './ExpoGaodeMapView';
6
6
  export type { MapViewRef } from './ExpoGaodeMapView';
7
7
  export { Marker, Polyline, Polygon, Circle, HeatMap, MultiPoint, Cluster, } from './components/overlays';
8
+ export { requireModule, OptionalModules, getInstalledModules, printModuleInfo, createLazyLoader, } from './utils/ModuleLoader';
8
9
  export { default } from './ExpoGaodeMapModule';
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAGrE,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxE,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,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAGrE,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxE,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,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC"}
package/build/index.js CHANGED
@@ -7,6 +7,8 @@ export { default as ExpoGaodeMapModule } from './ExpoGaodeMapModule';
7
7
  export { default as MapView } from './ExpoGaodeMapView';
8
8
  // 导出覆盖物组件
9
9
  export { Marker, Polyline, Polygon, Circle, HeatMap, MultiPoint, Cluster, } from './components/overlays';
10
+ // 导出模块检测工具
11
+ export { requireModule, OptionalModules, getInstalledModules, printModuleInfo, createLazyLoader, } from './utils/ModuleLoader';
10
12
  // 默认导出原生模块
11
13
  export { default } from './ExpoGaodeMapModule';
12
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,SAAS;AACT,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AAExB,qBAAqB;AACrB,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAKrE,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,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["// 导出类型定义\nexport * from './ExpoGaodeMap.types';\nexport * from './types';\n\n// 导出原生模块 - 直接使用,无需封装\nexport { default as ExpoGaodeMapModule } from './ExpoGaodeMapModule';\n\n// 从 ExpoGaodeMapModule 重新导出类型,方便使用\nexport type { SDKConfig, PermissionStatus } 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 { default } from './ExpoGaodeMapModule';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,SAAS;AACT,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AAExB,qBAAqB;AACrB,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAKrE,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,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["\n// 导出类型定义\nexport * from './ExpoGaodeMap.types';\nexport * from './types';\n\n// 导出原生模块 - 直接使用,无需封装\nexport { default as ExpoGaodeMapModule } from './ExpoGaodeMapModule';\n\n// 从 ExpoGaodeMapModule 重新导出类型,方便使用\nexport type { SDKConfig, PermissionStatus } 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 { default } from './ExpoGaodeMapModule';\n"]}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * 模块检测器 - 用于检测可选模块是否已安装
3
+ */
4
+ /**
5
+ * 可选模块名称常量
6
+ */
7
+ export declare const OptionalModules: {
8
+ readonly SEARCH: "@expo-gaode-map/search";
9
+ readonly NAVIGATION: "@expo-gaode-map/navigation";
10
+ readonly ROUTE: "@expo-gaode-map/route";
11
+ readonly GEOCODER: "@expo-gaode-map/geocoder";
12
+ };
13
+ /**
14
+ * 延迟加载可选模块
15
+ * 使用示例:
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { OptionalModules, lazyLoad } from 'expo-gaode-map';
20
+ *
21
+ * let SearchModule = null;
22
+ *
23
+ * function loadSearch() {
24
+ * if (SearchModule == null) {
25
+ * try {
26
+ * SearchModule = require('expo-gaode-map-search');
27
+ * } catch (error) {
28
+ * console.warn('搜索模块未安装');
29
+ * return null;
30
+ * }
31
+ * }
32
+ * return SearchModule;
33
+ * }
34
+ *
35
+ * // 使用
36
+ * const search = loadSearch();
37
+ * if (search) {
38
+ * const results = await search.searchPOI({ keyword: '餐厅' });
39
+ * }
40
+ * ```
41
+ */
42
+ /**
43
+ * 检查必需模块,如果未安装则抛出错误
44
+ * @param moduleName 模块名称
45
+ * @param featureName 功能名称(用于错误提示)
46
+ */
47
+ export declare function requireModule(moduleName: string, featureName: string): void;
48
+ /**
49
+ * 获取已安装的可选模块列表
50
+ * 注意: 此函数无法在运行时准确检测,仅作为文档说明
51
+ */
52
+ export declare function getInstalledModules(): string[];
53
+ /**
54
+ * 打印已安装模块信息(用于调试)
55
+ */
56
+ export declare function printModuleInfo(): void;
57
+ /**
58
+ * 创建延迟加载器
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * import { createLazyLoader } from 'expo-gaode-map';
63
+ *
64
+ * const loadSearch = createLazyLoader(() => require('expo-gaode-map-search'));
65
+ *
66
+ * // 使用时
67
+ * const SearchModule = loadSearch();
68
+ * if (SearchModule) {
69
+ * const results = await SearchModule.searchPOI({ keyword: '餐厅' });
70
+ * }
71
+ * ```
72
+ */
73
+ export declare function createLazyLoader<T>(loader: () => T): () => T | null;
74
+ //# sourceMappingURL=ModuleLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModuleLoader.d.ts","sourceRoot":"","sources":["../../src/utils/ModuleLoader.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;CAKlB,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAM3E;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,EAAE,CAM9C;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAQtC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,IAAI,CAgBnE"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * 模块检测器 - 用于检测可选模块是否已安装
3
+ */
4
+ /**
5
+ * 可选模块名称常量
6
+ */
7
+ export const OptionalModules = {
8
+ SEARCH: '@expo-gaode-map/search',
9
+ NAVIGATION: '@expo-gaode-map/navigation',
10
+ ROUTE: '@expo-gaode-map/route',
11
+ GEOCODER: '@expo-gaode-map/geocoder',
12
+ };
13
+ /**
14
+ * 延迟加载可选模块
15
+ * 使用示例:
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { OptionalModules, lazyLoad } from 'expo-gaode-map';
20
+ *
21
+ * let SearchModule = null;
22
+ *
23
+ * function loadSearch() {
24
+ * if (SearchModule == null) {
25
+ * try {
26
+ * SearchModule = require('expo-gaode-map-search');
27
+ * } catch (error) {
28
+ * console.warn('搜索模块未安装');
29
+ * return null;
30
+ * }
31
+ * }
32
+ * return SearchModule;
33
+ * }
34
+ *
35
+ * // 使用
36
+ * const search = loadSearch();
37
+ * if (search) {
38
+ * const results = await search.searchPOI({ keyword: '餐厅' });
39
+ * }
40
+ * ```
41
+ */
42
+ /**
43
+ * 检查必需模块,如果未安装则抛出错误
44
+ * @param moduleName 模块名称
45
+ * @param featureName 功能名称(用于错误提示)
46
+ */
47
+ export function requireModule(moduleName, featureName) {
48
+ console.warn(`[expo-gaode-map] 使用 ${featureName} 需要安装 ${moduleName}。\n` +
49
+ `请运行: npm install ${moduleName}\n` +
50
+ `然后使用 try-catch 包裹 require('${moduleName}') 来加载`);
51
+ }
52
+ /**
53
+ * 获取已安装的可选模块列表
54
+ * 注意: 此函数无法在运行时准确检测,仅作为文档说明
55
+ */
56
+ export function getInstalledModules() {
57
+ console.warn('[expo-gaode-map] getInstalledModules() 无法在运行时检测。\n' +
58
+ '请在编译时检查 package.json 中安装的模块');
59
+ return [];
60
+ }
61
+ /**
62
+ * 打印已安装模块信息(用于调试)
63
+ */
64
+ export function printModuleInfo() {
65
+ console.log('[expo-gaode-map] 核心模块: 已加载');
66
+ console.log('[expo-gaode-map] 可选模块检测:');
67
+ console.log(' - 使用 try-catch 包裹 require() 来检测可选模块');
68
+ console.log(' - 可用的可选模块:');
69
+ Object.entries(OptionalModules).forEach(([key, value]) => {
70
+ console.log(` - ${key}: ${value}`);
71
+ });
72
+ }
73
+ /**
74
+ * 创建延迟加载器
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * import { createLazyLoader } from 'expo-gaode-map';
79
+ *
80
+ * const loadSearch = createLazyLoader(() => require('expo-gaode-map-search'));
81
+ *
82
+ * // 使用时
83
+ * const SearchModule = loadSearch();
84
+ * if (SearchModule) {
85
+ * const results = await SearchModule.searchPOI({ keyword: '餐厅' });
86
+ * }
87
+ * ```
88
+ */
89
+ export function createLazyLoader(loader) {
90
+ let cached = null;
91
+ let attempted = false;
92
+ return () => {
93
+ if (!attempted) {
94
+ attempted = true;
95
+ try {
96
+ cached = loader();
97
+ }
98
+ catch (error) {
99
+ console.warn('[expo-gaode-map] 模块加载失败:', error);
100
+ cached = null;
101
+ }
102
+ }
103
+ return cached;
104
+ };
105
+ }
106
+ //# sourceMappingURL=ModuleLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModuleLoader.js","sourceRoot":"","sources":["../../src/utils/ModuleLoader.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,MAAM,EAAE,wBAAwB;IAChC,UAAU,EAAE,4BAA4B;IACxC,KAAK,EAAE,uBAAuB;IAC9B,QAAQ,EAAE,0BAA0B;CAC5B,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,UAAkB,EAAE,WAAmB;IACnE,OAAO,CAAC,IAAI,CACV,uBAAuB,WAAW,SAAS,UAAU,KAAK;QAC1D,oBAAoB,UAAU,IAAI;QAClC,8BAA8B,UAAU,QAAQ,CACjD,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,CAAC,IAAI,CACV,oDAAoD;QACpD,6BAA6B,CAC9B,CAAC;IACF,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;IAC1C,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IACxC,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;IACrD,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAC5B,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACvD,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,KAAK,KAAK,EAAE,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,gBAAgB,CAAI,MAAe;IACjD,IAAI,MAAM,GAAa,IAAI,CAAC;IAC5B,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,OAAO,GAAG,EAAE;QACV,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,SAAS,GAAG,IAAI,CAAC;YACjB,IAAI,CAAC;gBACH,MAAM,GAAG,MAAM,EAAE,CAAC;YACpB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,IAAI,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;gBAChD,MAAM,GAAG,IAAI,CAAC;YAChB,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * 模块检测器 - 用于检测可选模块是否已安装\n */\n\n/**\n * 可选模块名称常量\n */\nexport const OptionalModules = {\n SEARCH: '@expo-gaode-map/search',\n NAVIGATION: '@expo-gaode-map/navigation',\n ROUTE: '@expo-gaode-map/route',\n GEOCODER: '@expo-gaode-map/geocoder',\n} as const;\n\n/**\n * 延迟加载可选模块\n * 使用示例:\n * \n * @example\n * ```typescript\n * import { OptionalModules, lazyLoad } from 'expo-gaode-map';\n * \n * let SearchModule = null;\n * \n * function loadSearch() {\n * if (SearchModule == null) {\n * try {\n * SearchModule = require('expo-gaode-map-search');\n * } catch (error) {\n * console.warn('搜索模块未安装');\n * return null;\n * }\n * }\n * return SearchModule;\n * }\n * \n * // 使用\n * const search = loadSearch();\n * if (search) {\n * const results = await search.searchPOI({ keyword: '餐厅' });\n * }\n * ```\n */\n\n/**\n * 检查必需模块,如果未安装则抛出错误\n * @param moduleName 模块名称\n * @param featureName 功能名称(用于错误提示)\n */\nexport function requireModule(moduleName: string, featureName: string): void {\n console.warn(\n `[expo-gaode-map] 使用 ${featureName} 需要安装 ${moduleName}。\\n` +\n `请运行: npm install ${moduleName}\\n` +\n `然后使用 try-catch 包裹 require('${moduleName}') 来加载`\n );\n}\n\n/**\n * 获取已安装的可选模块列表\n * 注意: 此函数无法在运行时准确检测,仅作为文档说明\n */\nexport function getInstalledModules(): string[] {\n console.warn(\n '[expo-gaode-map] getInstalledModules() 无法在运行时检测。\\n' +\n '请在编译时检查 package.json 中安装的模块'\n );\n return [];\n}\n\n/**\n * 打印已安装模块信息(用于调试)\n */\nexport function printModuleInfo(): void {\n console.log('[expo-gaode-map] 核心模块: 已加载');\n console.log('[expo-gaode-map] 可选模块检测:');\n console.log(' - 使用 try-catch 包裹 require() 来检测可选模块');\n console.log(' - 可用的可选模块:');\n Object.entries(OptionalModules).forEach(([key, value]) => {\n console.log(` - ${key}: ${value}`);\n });\n}\n\n/**\n * 创建延迟加载器\n * \n * @example\n * ```typescript\n * import { createLazyLoader } from 'expo-gaode-map';\n * \n * const loadSearch = createLazyLoader(() => require('expo-gaode-map-search'));\n * \n * // 使用时\n * const SearchModule = loadSearch();\n * if (SearchModule) {\n * const results = await SearchModule.searchPOI({ keyword: '餐厅' });\n * }\n * ```\n */\nexport function createLazyLoader<T>(loader: () => T): () => T | null {\n let cached: T | null = null;\n let attempted = false;\n\n return () => {\n if (!attempted) {\n attempted = true;\n try {\n cached = loader();\n } catch (error) {\n console.warn('[expo-gaode-map] 模块加载失败:', error);\n cached = null;\n }\n }\n return cached;\n };\n}"]}
@@ -19,8 +19,12 @@ Pod::Spec.new do |s|
19
19
  s.static_framework = true
20
20
 
21
21
  s.dependency 'ExpoModulesCore'
22
+
23
+ # 核心依赖 - 3D地图和定位
22
24
  s.dependency 'AMap3DMap', '10.0.600'
23
- s.dependency "AMapLocation"
25
+ s.dependency 'AMapLocation'
26
+
27
+
24
28
  # Swift/Objective-C compatibility
25
29
  s.pod_target_xcconfig = {
26
30
  'DEFINES_MODULE' => 'YES',
@@ -24,6 +24,8 @@ public class ExpoGaodeMapModule: Module {
24
24
  OnCreate {
25
25
  MAMapView.updatePrivacyAgree(AMapPrivacyAgreeStatus.didAgree)
26
26
  MAMapView.updatePrivacyShow(AMapPrivacyShowStatus.didShow, privacyInfo: AMapPrivacyInfoStatus.didContain)
27
+
28
+
27
29
  }
28
30
 
29
31
  // ==================== SDK 初始化 ====================
package/package.json CHANGED
@@ -1,23 +1,9 @@
1
1
  {
2
2
  "name": "expo-gaode-map",
3
- "version": "2.0.0",
3
+ "version": "2.1.0-beta.0",
4
4
  "description": "一个功能完整的高德地图 React Native 组件库,基于 Expo Modules 开发,提供地图显示、定位、覆盖物等功能。",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
7
- "scripts": {
8
- "build": "expo-module build && npm run build:plugin",
9
- "build:plugin": "tsc --project plugin/tsconfig.json",
10
- "clean": "expo-module clean && rm -rf plugin/build",
11
- "lint": "expo-module lint",
12
- "test": "expo-module test",
13
- "prepare": "expo-module prepare && npm run build:plugin",
14
- "prepublishOnly": "expo-module prepublishOnly",
15
- "expo-module": "expo-module",
16
- "open:ios": "xed example/ios",
17
- "open:android": "open -a \"Android Studio\" example/android",
18
- "publish:next": "npm publish --tag next",
19
- "publish:latest": "npm publish --tag latest"
20
- },
21
7
  "keywords": [
22
8
  "react-native",
23
9
  "expo",
@@ -47,5 +33,17 @@
47
33
  "expo": "*",
48
34
  "react": "*",
49
35
  "react-native": "*"
36
+ },
37
+ "scripts": {
38
+ "build": "expo-module build && pnpm run build:plugin",
39
+ "build:plugin": "tsc --project plugin/tsconfig.json",
40
+ "clean": "expo-module clean && rm -rf plugin/build",
41
+ "lint": "expo-module lint",
42
+ "test": "expo-module test",
43
+ "expo-module": "expo-module",
44
+ "open:ios": "xed example/ios",
45
+ "open:android": "open -a \"Android Studio\" example/android",
46
+ "publish:next": "pnpm publish --tag next",
47
+ "publish:latest": "pnpm publish --tag latest"
50
48
  }
51
- }
49
+ }
@@ -11,6 +11,8 @@ export type GaodeMapPluginProps = {
11
11
  enableLocation?: boolean;
12
12
  /** iOS 定位权限描述 */
13
13
  locationDescription?: string;
14
+ /** 是否启用后台定位(Android & iOS) */
15
+ enableBackgroundLocation?: boolean;
14
16
  };
15
17
  /**
16
18
  * 导出为可运行一次的插件