expo-gaode-map-navigation 1.0.1-next.2 → 1.0.1-next.3
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-gaode-map-navigation",
|
|
3
|
-
"version": "1.0.1-next.
|
|
3
|
+
"version": "1.0.1-next.3",
|
|
4
4
|
"description": "高德地图导航功能模块 - 路径规划、导航引导,独立版本包含完整地图功能",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"android",
|
|
10
10
|
"ios",
|
|
11
11
|
"app.plugin.js",
|
|
12
|
-
"expo-module.config.json"
|
|
12
|
+
"expo-module.config.json",
|
|
13
|
+
"plugin/build"
|
|
13
14
|
],
|
|
14
15
|
"keywords": [
|
|
15
16
|
"react-native",
|
|
@@ -32,6 +33,7 @@
|
|
|
32
33
|
"supercluster": "^8.0.1"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
36
|
+
"@expo/config-plugins": "^9.1.7",
|
|
35
37
|
"@types/react": "~19.1.0",
|
|
36
38
|
"expo": "^54.0.18",
|
|
37
39
|
"expo-module-scripts": "^5.0.7",
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
/** 是否启用后台定位(Android & iOS) */
|
|
15
|
+
enableBackgroundLocation?: boolean;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* 导出为可运行一次的插件
|
|
19
|
+
* 这确保插件只会运行一次,即使在配置中被多次引用
|
|
20
|
+
*/
|
|
21
|
+
declare const _default: ConfigPlugin<GaodeMapPluginProps>;
|
|
22
|
+
export default _default;
|
|
@@ -0,0 +1,169 @@
|
|
|
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
|
+
// 使用时定位权限(必需)
|
|
17
|
+
config.modResults.NSLocationWhenInUseUsageDescription = description;
|
|
18
|
+
// 后台定位权限(可选)
|
|
19
|
+
if (props.enableBackgroundLocation) {
|
|
20
|
+
config.modResults.NSLocationAlwaysUsageDescription = description;
|
|
21
|
+
config.modResults.NSLocationAlwaysAndWhenInUseUsageDescription = description;
|
|
22
|
+
// 添加后台定位模式
|
|
23
|
+
if (!config.modResults.UIBackgroundModes) {
|
|
24
|
+
config.modResults.UIBackgroundModes = [];
|
|
25
|
+
}
|
|
26
|
+
if (!config.modResults.UIBackgroundModes.includes('location')) {
|
|
27
|
+
config.modResults.UIBackgroundModes.push('location');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return config;
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* iOS: 注意 - 不再需要修改 AppDelegate
|
|
36
|
+
*
|
|
37
|
+
* 高德地图 SDK 已经支持从 Info.plist 自动读取 API Key
|
|
38
|
+
* 并且我们在 ExpoGaodeMapModule.swift 中提供了 initSDK 方法
|
|
39
|
+
* 用户可以选择以下任一方式初始化:
|
|
40
|
+
* 1. 通过 Info.plist 中的 AMapApiKey 字段(自动读取)
|
|
41
|
+
* 2. 通过 JavaScript 调用 ExpoGaodeMap.initSDK({ iosKey: 'your-key' })
|
|
42
|
+
*/
|
|
43
|
+
/**
|
|
44
|
+
* Android: 修改 AndroidManifest.xml 添加 API Key 和权限
|
|
45
|
+
*/
|
|
46
|
+
const withGaodeMapAndroidManifest = (config, props) => {
|
|
47
|
+
return (0, config_plugins_1.withAndroidManifest)(config, (config) => {
|
|
48
|
+
const androidManifest = config.modResults.manifest;
|
|
49
|
+
// 添加基础权限(高德地图 SDK 必需)
|
|
50
|
+
const basePermissions = [
|
|
51
|
+
'android.permission.ACCESS_COARSE_LOCATION',
|
|
52
|
+
'android.permission.ACCESS_FINE_LOCATION',
|
|
53
|
+
'android.permission.ACCESS_NETWORK_STATE',
|
|
54
|
+
'android.permission.ACCESS_WIFI_STATE',
|
|
55
|
+
'android.permission.READ_PHONE_STATE',
|
|
56
|
+
'android.permission.BLUETOOTH',
|
|
57
|
+
'android.permission.BLUETOOTH_ADMIN',
|
|
58
|
+
];
|
|
59
|
+
if (!androidManifest['uses-permission']) {
|
|
60
|
+
androidManifest['uses-permission'] = [];
|
|
61
|
+
}
|
|
62
|
+
basePermissions.forEach((permission) => {
|
|
63
|
+
const hasPermission = androidManifest['uses-permission']?.some((item) => item.$?.['android:name'] === permission);
|
|
64
|
+
if (!hasPermission) {
|
|
65
|
+
androidManifest['uses-permission']?.push({
|
|
66
|
+
$: { 'android:name': permission },
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
// 后台定位权限(可选,仅在 enableBackgroundLocation 为 true 时添加)
|
|
71
|
+
if (props.enableBackgroundLocation) {
|
|
72
|
+
const backgroundPermissions = [
|
|
73
|
+
'android.permission.ACCESS_BACKGROUND_LOCATION',
|
|
74
|
+
'android.permission.FOREGROUND_SERVICE',
|
|
75
|
+
'android.permission.FOREGROUND_SERVICE_LOCATION',
|
|
76
|
+
];
|
|
77
|
+
if (!androidManifest['uses-permission']) {
|
|
78
|
+
androidManifest['uses-permission'] = [];
|
|
79
|
+
}
|
|
80
|
+
backgroundPermissions.forEach((permission) => {
|
|
81
|
+
const hasPermission = androidManifest['uses-permission']?.some((item) => item.$?.['android:name'] === permission);
|
|
82
|
+
if (!hasPermission) {
|
|
83
|
+
androidManifest['uses-permission']?.push({
|
|
84
|
+
$: { 'android:name': permission },
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
// 添加前台服务(如果启用后台定位)
|
|
90
|
+
const mainApplication = androidManifest.application?.[0];
|
|
91
|
+
if (mainApplication && props.enableBackgroundLocation) {
|
|
92
|
+
if (!mainApplication['service']) {
|
|
93
|
+
mainApplication['service'] = [];
|
|
94
|
+
}
|
|
95
|
+
// 检查是否已存在 LocationForegroundService
|
|
96
|
+
const hasService = mainApplication['service'].some((item) => item.$?.['android:name'] === 'expo.modules.gaodemap.services.LocationForegroundService');
|
|
97
|
+
if (!hasService) {
|
|
98
|
+
mainApplication['service'].push({
|
|
99
|
+
$: {
|
|
100
|
+
'android:name': 'expo.modules.gaodemap.services.LocationForegroundService',
|
|
101
|
+
'android:enabled': 'true',
|
|
102
|
+
'android:exported': 'false',
|
|
103
|
+
'android:foregroundServiceType': 'location',
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// 添加 API Key 到 application 标签
|
|
109
|
+
if (mainApplication && props.androidApiKey) {
|
|
110
|
+
if (!mainApplication['meta-data']) {
|
|
111
|
+
mainApplication['meta-data'] = [];
|
|
112
|
+
}
|
|
113
|
+
// 检查是否已存在
|
|
114
|
+
const hasApiKey = mainApplication['meta-data'].some((item) => item.$?.['android:name'] === 'com.amap.api.v2.apikey');
|
|
115
|
+
if (!hasApiKey) {
|
|
116
|
+
mainApplication['meta-data'].push({
|
|
117
|
+
$: {
|
|
118
|
+
'android:name': 'com.amap.api.v2.apikey',
|
|
119
|
+
'android:value': props.androidApiKey,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
// 更新现有的 API Key
|
|
125
|
+
const apiKeyIndex = mainApplication['meta-data'].findIndex((item) => item.$?.['android:name'] === 'com.amap.api.v2.apikey');
|
|
126
|
+
if (apiKeyIndex !== -1) {
|
|
127
|
+
mainApplication['meta-data'][apiKeyIndex].$ = {
|
|
128
|
+
'android:name': 'com.amap.api.v2.apikey',
|
|
129
|
+
'android:value': props.androidApiKey,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return config;
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Android: 修改 app/build.gradle(预留扩展)
|
|
139
|
+
*/
|
|
140
|
+
const withGaodeMapAppBuildGradle = (config, props) => {
|
|
141
|
+
return (0, config_plugins_1.withAppBuildGradle)(config, (config) => {
|
|
142
|
+
// Android 3D 地图 SDK 10.0+ 已内置搜索功能
|
|
143
|
+
// 不需要额外的 Gradle 配置
|
|
144
|
+
return config;
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* 主插件函数 - 组合所有修改器
|
|
149
|
+
*/
|
|
150
|
+
const withGaodeMap = (config, props = {}) => {
|
|
151
|
+
// 验证配置
|
|
152
|
+
if (!props.iosApiKey && !props.androidApiKey) {
|
|
153
|
+
config_plugins_1.WarningAggregator.addWarningIOS('expo-gaode-map-navigation', '未配置 API Key。请在 app.json 的 plugins 中配置 iosApiKey 和 androidApiKey');
|
|
154
|
+
}
|
|
155
|
+
// 应用 iOS 配置
|
|
156
|
+
config = withGaodeMapInfoPlist(config, props);
|
|
157
|
+
// 注意:不再需要修改 AppDelegate,因为:
|
|
158
|
+
// 1. SDK 会自动从 Info.plist 读取 AMapApiKey
|
|
159
|
+
// 2. 可以通过 ExpoGaodeMapModule.initSDK() 方法初始化
|
|
160
|
+
// 应用 Android 配置
|
|
161
|
+
config = withGaodeMapAndroidManifest(config, props);
|
|
162
|
+
config = withGaodeMapAppBuildGradle(config, props);
|
|
163
|
+
return config;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* 导出为可运行一次的插件
|
|
167
|
+
* 这确保插件只会运行一次,即使在配置中被多次引用
|
|
168
|
+
*/
|
|
169
|
+
exports.default = (0, config_plugins_1.createRunOncePlugin)(withGaodeMap, 'expo-gaode-map-navigation', '1.0.0');
|