expo-gaode-map 2.0.0-alpha.6 → 2.0.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/DEPLOY_DOCS.md +209 -0
- package/PUBLISHING.md +173 -155
- package/README.en.md +1 -25
- package/README.md +26 -456
- package/RELEASE_CHECKLIST.md +146 -0
- package/RELEASE_v2.0.0.md +59 -0
- package/app.plugin.js +11 -0
- package/ios/modules/LocationManager.swift +4 -3
- package/package.json +8 -5
- package/plugin/README.md +52 -0
- package/plugin/build/withGaodeMap.d.ts +20 -0
- package/plugin/build/withGaodeMap.js +147 -0
- package/plugin/tsconfig.tsbuildinfo +1 -0
- package/docs/API.en.md +0 -408
- package/docs/API.md +0 -494
- package/docs/ARCHITECTURE.en.md +0 -423
- package/docs/ARCHITECTURE.md +0 -423
- package/docs/EXAMPLES.en.md +0 -651
- package/docs/EXAMPLES.md +0 -922
- package/docs/INITIALIZATION.en.md +0 -346
- package/docs/INITIALIZATION.md +0 -335
- package/docs/MIGRATION.md +0 -423
- package/docs/RELEASE_GUIDE.md +0 -178
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
## 🎉 v2.0.0 正式版发布
|
|
2
|
+
|
|
3
|
+
一个功能完整的高德地图 React Native 组件库,基于 Expo Modules 开发。
|
|
4
|
+
|
|
5
|
+
## ✨ 核心特性
|
|
6
|
+
|
|
7
|
+
- 🗺️ **完整的地图功能** - 多种地图类型、相机控制、手势配置
|
|
8
|
+
- 📍 **精准定位服务** - 连续定位、单次定位、逆地理编码
|
|
9
|
+
- 🎨 **丰富的覆盖物** - Marker、Circle、Polyline、Polygon、HeatMap、Cluster
|
|
10
|
+
- 💎 **完整 TypeScript 支持** - 零 any 类型,完美的类型推导
|
|
11
|
+
- 🚀 **基于 Expo Modules** - 现代化的原生模块开发体验
|
|
12
|
+
- 📱 **跨平台支持** - 同时支持 Android 和 iOS
|
|
13
|
+
- 🔄 **新旧架构兼容** - 支持 React Native Paper & Fabric
|
|
14
|
+
|
|
15
|
+
## 📦 安装
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install expo-gaode-map
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 🚀 快速开始
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { MapView, ExpoGaodeMapModule } from 'expo-gaode-map';
|
|
25
|
+
|
|
26
|
+
// 初始化
|
|
27
|
+
ExpoGaodeMapModule.initSDK({
|
|
28
|
+
androidKey: 'your-android-key',
|
|
29
|
+
iosKey: 'your-ios-key',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// 使用地图
|
|
33
|
+
<MapView
|
|
34
|
+
style={{ flex: 1 }}
|
|
35
|
+
myLocationEnabled={true}
|
|
36
|
+
/>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 📖 完整文档
|
|
40
|
+
|
|
41
|
+
**👉 [在线文档](https://TomWq.github.io/expo-gaode-map/)**
|
|
42
|
+
|
|
43
|
+
- [快速开始](https://TomWq.github.io/expo-gaode-map/guide/getting-started.html)
|
|
44
|
+
- [API 文档](https://TomWq.github.io/expo-gaode-map/api/)
|
|
45
|
+
- [使用示例](https://TomWq.github.io/expo-gaode-map/examples/)
|
|
46
|
+
|
|
47
|
+
## 🔄 从 v1.x 升级
|
|
48
|
+
|
|
49
|
+
查看 [迁移指南](https://github.com/TomWq/expo-gaode-map/blob/main/docs/MIGRATION.md)
|
|
50
|
+
|
|
51
|
+
## 📮 反馈与支持
|
|
52
|
+
|
|
53
|
+
- 📝 [提交 Issue](https://github.com/TomWq/expo-gaode-map/issues)
|
|
54
|
+
- 💬 [参与讨论](https://github.com/TomWq/expo-gaode-map/discussions)
|
|
55
|
+
- 💬 QQ 群:952241387
|
|
56
|
+
|
|
57
|
+
## 📄 许可证
|
|
58
|
+
|
|
59
|
+
MIT License
|
package/app.plugin.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
// Expo Config Plugin 入口文件
|
|
3
|
+
// 这个文件会在用户运行 npx expo prebuild 时被调用
|
|
4
|
+
|
|
5
|
+
const { createRunOncePlugin } = require('@expo/config-plugins');
|
|
6
|
+
|
|
7
|
+
// 导入编译后的插件
|
|
8
|
+
const withGaodeMap = require('./plugin/build/withGaodeMap').default;
|
|
9
|
+
|
|
10
|
+
// 导出插件
|
|
11
|
+
module.exports = withGaodeMap;
|
|
@@ -178,11 +178,12 @@ class LocationManager: NSObject, AMapLocationManagerDelegate {
|
|
|
178
178
|
private func initLocationManager() {
|
|
179
179
|
locationManager = AMapLocationManager()
|
|
180
180
|
locationManager?.delegate = self
|
|
181
|
-
//
|
|
181
|
+
// 推荐配置:百米精度,快速定位
|
|
182
182
|
locationManager?.desiredAccuracy = kCLLocationAccuracyHundredMeters
|
|
183
183
|
locationManager?.distanceFilter = 10
|
|
184
|
-
|
|
185
|
-
locationManager?.
|
|
184
|
+
// 增加超时时间,避免首次授权时超时(首次定位建议10秒以上)
|
|
185
|
+
locationManager?.locationTimeout = 10 // 10秒超时
|
|
186
|
+
locationManager?.reGeocodeTimeout = 5 // 5秒超时
|
|
186
187
|
locationManager?.locatingWithReGeocode = true
|
|
187
188
|
|
|
188
189
|
// iOS 9 之前:防止后台被系统挂起(默认关闭,用户可通过 setPausesLocationUpdatesAutomatically 配置)
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-gaode-map",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "一个功能完整的高德地图 React Native 组件库,基于 Expo Modules 开发,提供地图显示、定位、覆盖物等功能。",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "expo-module build",
|
|
9
|
-
"
|
|
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",
|
|
10
11
|
"lint": "expo-module lint",
|
|
11
12
|
"test": "expo-module test",
|
|
12
|
-
"prepare": "expo-module prepare",
|
|
13
|
+
"prepare": "expo-module prepare && npm run build:plugin",
|
|
13
14
|
"prepublishOnly": "expo-module prepublishOnly",
|
|
14
15
|
"expo-module": "expo-module",
|
|
15
16
|
"open:ios": "xed example/ios",
|
|
@@ -35,10 +36,12 @@
|
|
|
35
36
|
"supercluster": "^8.0.1"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
39
|
+
"@expo/config-plugins": "^9.1.7",
|
|
38
40
|
"@types/react": "~19.1.0",
|
|
39
41
|
"expo": "^54.0.18",
|
|
40
42
|
"expo-module-scripts": "^5.0.7",
|
|
41
|
-
"react-native": "0.81.5"
|
|
43
|
+
"react-native": "0.81.5",
|
|
44
|
+
"typescript": "^5.9.3"
|
|
42
45
|
},
|
|
43
46
|
"peerDependencies": {
|
|
44
47
|
"expo": "*",
|
package/plugin/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Expo Config Plugin for expo-gaode-map
|
|
2
|
+
|
|
3
|
+
这是 `expo-gaode-map` 的 Expo Config Plugin 实现。
|
|
4
|
+
|
|
5
|
+
## 功能
|
|
6
|
+
|
|
7
|
+
- 自动配置 iOS 和 Android 平台的高德地图 API Key
|
|
8
|
+
- 自动添加定位权限
|
|
9
|
+
- 自动初始化高德地图 SDK
|
|
10
|
+
|
|
11
|
+
## 开发
|
|
12
|
+
|
|
13
|
+
### 构建插件
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm run build:plugin
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### 目录结构
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
plugin/
|
|
23
|
+
├── src/
|
|
24
|
+
│ └── withGaodeMap.ts # 插件源代码
|
|
25
|
+
├── build/ # 编译输出目录
|
|
26
|
+
├── tsconfig.json # TypeScript 配置
|
|
27
|
+
└── README.md # 本文件
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## 使用方法
|
|
31
|
+
|
|
32
|
+
请查看主文档: [CONFIG_PLUGIN.md](../docs/CONFIG_PLUGIN.md)
|
|
33
|
+
|
|
34
|
+
## 技术细节
|
|
35
|
+
|
|
36
|
+
### 修改的文件
|
|
37
|
+
|
|
38
|
+
**iOS:**
|
|
39
|
+
- `Info.plist` - 添加 API Key 和权限
|
|
40
|
+
- `AppDelegate.m` - 添加 SDK 初始化代码
|
|
41
|
+
|
|
42
|
+
**Android:**
|
|
43
|
+
- `AndroidManifest.xml` - 添加 API Key 和权限
|
|
44
|
+
|
|
45
|
+
### 依赖
|
|
46
|
+
|
|
47
|
+
- `@expo/config-plugins` - Expo 配置插件核心库
|
|
48
|
+
|
|
49
|
+
## 参考
|
|
50
|
+
|
|
51
|
+
- [Expo Config Plugins](https://docs.expo.dev/config-plugins/introduction/)
|
|
52
|
+
- [Creating a Config Plugin](https://docs.expo.dev/config-plugins/plugins-and-mods/)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ConfigPlugin } from '@expo/config-plugins';
|
|
2
|
+
/**
|
|
3
|
+
* 高德地图插件配置类型
|
|
4
|
+
*/
|
|
5
|
+
export type GaodeMapPluginProps = {
|
|
6
|
+
/** iOS 平台 API Key */
|
|
7
|
+
iosApiKey?: string;
|
|
8
|
+
/** Android 平台 API Key */
|
|
9
|
+
androidApiKey?: string;
|
|
10
|
+
/** 是否启用定位功能 */
|
|
11
|
+
enableLocation?: boolean;
|
|
12
|
+
/** iOS 定位权限描述 */
|
|
13
|
+
locationDescription?: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* 导出为可运行一次的插件
|
|
17
|
+
* 这确保插件只会运行一次,即使在配置中被多次引用
|
|
18
|
+
*/
|
|
19
|
+
declare const _default: ConfigPlugin<GaodeMapPluginProps>;
|
|
20
|
+
export default _default;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_plugins_1 = require("@expo/config-plugins");
|
|
4
|
+
/**
|
|
5
|
+
* iOS: 修改 Info.plist 添加 API Key 和权限
|
|
6
|
+
*/
|
|
7
|
+
const withGaodeMapInfoPlist = (config, props) => {
|
|
8
|
+
return (0, config_plugins_1.withInfoPlist)(config, (config) => {
|
|
9
|
+
// 添加高德地图 API Key
|
|
10
|
+
if (props.iosApiKey) {
|
|
11
|
+
config.modResults.AMapApiKey = props.iosApiKey;
|
|
12
|
+
}
|
|
13
|
+
// 添加定位相关权限
|
|
14
|
+
if (props.enableLocation !== false) {
|
|
15
|
+
const description = props.locationDescription || '需要访问您的位置信息以提供地图服务';
|
|
16
|
+
config.modResults.NSLocationWhenInUseUsageDescription = description;
|
|
17
|
+
config.modResults.NSLocationAlwaysUsageDescription = description;
|
|
18
|
+
config.modResults.NSLocationAlwaysAndWhenInUseUsageDescription = description;
|
|
19
|
+
}
|
|
20
|
+
// 添加后台定位模式(如果需要)
|
|
21
|
+
if (props.enableLocation !== false) {
|
|
22
|
+
if (!config.modResults.UIBackgroundModes) {
|
|
23
|
+
config.modResults.UIBackgroundModes = [];
|
|
24
|
+
}
|
|
25
|
+
if (!config.modResults.UIBackgroundModes.includes('location')) {
|
|
26
|
+
config.modResults.UIBackgroundModes.push('location');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return config;
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* iOS: 修改 AppDelegate 添加初始化代码
|
|
34
|
+
*/
|
|
35
|
+
const withGaodeMapAppDelegate = (config, props) => {
|
|
36
|
+
return (0, config_plugins_1.withAppDelegate)(config, (config) => {
|
|
37
|
+
if (!props.iosApiKey) {
|
|
38
|
+
return config;
|
|
39
|
+
}
|
|
40
|
+
let contents = config.modResults.contents;
|
|
41
|
+
// 添加 import 语句
|
|
42
|
+
if (!contents.includes('#import <AMapFoundationKit/AMapFoundationKit.h>')) {
|
|
43
|
+
// 在 #import "AppDelegate.h" 之后添加
|
|
44
|
+
contents = contents.replace(/#import "AppDelegate.h"/g, `#import "AppDelegate.h"\n#import <AMapFoundationKit/AMapFoundationKit.h>`);
|
|
45
|
+
}
|
|
46
|
+
// 在 didFinishLaunchingWithOptions 方法中添加初始化代码
|
|
47
|
+
const initCode = ` [AMapServices sharedServices].apiKey = @"${props.iosApiKey}";`;
|
|
48
|
+
if (!contents.includes(initCode)) {
|
|
49
|
+
// 在 didFinishLaunchingWithOptions 方法的开始处添加
|
|
50
|
+
contents = contents.replace(/(- \(BOOL\)application:\(UIApplication \*\)application didFinishLaunchingWithOptions:\(NSDictionary \*\)launchOptions\s*\{)/g, `$1\n${initCode}`);
|
|
51
|
+
}
|
|
52
|
+
config.modResults.contents = contents;
|
|
53
|
+
return config;
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Android: 修改 AndroidManifest.xml 添加 API Key 和权限
|
|
58
|
+
*/
|
|
59
|
+
const withGaodeMapAndroidManifest = (config, props) => {
|
|
60
|
+
return (0, config_plugins_1.withAndroidManifest)(config, (config) => {
|
|
61
|
+
const androidManifest = config.modResults.manifest;
|
|
62
|
+
// 添加权限
|
|
63
|
+
if (props.enableLocation !== false) {
|
|
64
|
+
const permissions = [
|
|
65
|
+
'android.permission.ACCESS_COARSE_LOCATION',
|
|
66
|
+
'android.permission.ACCESS_FINE_LOCATION',
|
|
67
|
+
'android.permission.ACCESS_WIFI_STATE',
|
|
68
|
+
'android.permission.ACCESS_NETWORK_STATE',
|
|
69
|
+
'android.permission.CHANGE_WIFI_STATE',
|
|
70
|
+
'android.permission.INTERNET',
|
|
71
|
+
'android.permission.WRITE_EXTERNAL_STORAGE',
|
|
72
|
+
'android.permission.READ_EXTERNAL_STORAGE',
|
|
73
|
+
'android.permission.ACCESS_LOCATION_EXTRA_COMMANDS',
|
|
74
|
+
];
|
|
75
|
+
if (!androidManifest['uses-permission']) {
|
|
76
|
+
androidManifest['uses-permission'] = [];
|
|
77
|
+
}
|
|
78
|
+
permissions.forEach((permission) => {
|
|
79
|
+
const hasPermission = androidManifest['uses-permission']?.some((item) => item.$?.['android:name'] === permission);
|
|
80
|
+
if (!hasPermission) {
|
|
81
|
+
androidManifest['uses-permission']?.push({
|
|
82
|
+
$: { 'android:name': permission },
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
// 添加 API Key 到 application 标签
|
|
88
|
+
const mainApplication = androidManifest.application?.[0];
|
|
89
|
+
if (mainApplication && props.androidApiKey) {
|
|
90
|
+
if (!mainApplication['meta-data']) {
|
|
91
|
+
mainApplication['meta-data'] = [];
|
|
92
|
+
}
|
|
93
|
+
// 检查是否已存在
|
|
94
|
+
const hasApiKey = mainApplication['meta-data'].some((item) => item.$?.['android:name'] === 'com.amap.api.v2.apikey');
|
|
95
|
+
if (!hasApiKey) {
|
|
96
|
+
mainApplication['meta-data'].push({
|
|
97
|
+
$: {
|
|
98
|
+
'android:name': 'com.amap.api.v2.apikey',
|
|
99
|
+
'android:value': props.androidApiKey,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// 更新现有的 API Key
|
|
105
|
+
const apiKeyIndex = mainApplication['meta-data'].findIndex((item) => item.$?.['android:name'] === 'com.amap.api.v2.apikey');
|
|
106
|
+
if (apiKeyIndex !== -1) {
|
|
107
|
+
mainApplication['meta-data'][apiKeyIndex].$ = {
|
|
108
|
+
'android:name': 'com.amap.api.v2.apikey',
|
|
109
|
+
'android:value': props.androidApiKey,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return config;
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Android: 修改 app/build.gradle 添加依赖
|
|
119
|
+
*/
|
|
120
|
+
const withGaodeMapAppBuildGradle = (config, props) => {
|
|
121
|
+
return (0, config_plugins_1.withAppBuildGradle)(config, (config) => {
|
|
122
|
+
// 这里可以添加额外的 Gradle 配置,如果需要的话
|
|
123
|
+
// 例如添加 maven 仓库或其他依赖
|
|
124
|
+
return config;
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* 主插件函数 - 组合所有修改器
|
|
129
|
+
*/
|
|
130
|
+
const withGaodeMap = (config, props = {}) => {
|
|
131
|
+
// 验证配置
|
|
132
|
+
if (!props.iosApiKey && !props.androidApiKey) {
|
|
133
|
+
config_plugins_1.WarningAggregator.addWarningIOS('expo-gaode-map', '未配置 API Key。请在 app.json 的 plugins 中配置 iosApiKey 和 androidApiKey');
|
|
134
|
+
}
|
|
135
|
+
// 应用 iOS 配置
|
|
136
|
+
config = withGaodeMapInfoPlist(config, props);
|
|
137
|
+
config = withGaodeMapAppDelegate(config, props);
|
|
138
|
+
// 应用 Android 配置
|
|
139
|
+
config = withGaodeMapAndroidManifest(config, props);
|
|
140
|
+
config = withGaodeMapAppBuildGradle(config, props);
|
|
141
|
+
return config;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* 导出为可运行一次的插件
|
|
145
|
+
* 这确保插件只会运行一次,即使在配置中被多次引用
|
|
146
|
+
*/
|
|
147
|
+
exports.default = (0, config_plugins_1.createRunOncePlugin)(withGaodeMap, 'expo-gaode-map', '1.0.0');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./src/withgaodemap.ts"],"version":"5.9.3"}
|