capacitor-baidu-location 0.0.1
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/CapacitorBaiduLocation.podspec +23 -0
- package/Package.swift +44 -0
- package/README.md +376 -0
- package/android/build.gradle +71 -0
- package/android/src/main/AndroidManifest.xml +32 -0
- package/android/src/main/kotlin/com/hybrid/baidu/location/CPBaiduLocation.kt +246 -0
- package/android/src/main/kotlin/com/hybrid/baidu/location/CPBaiduLocationConfig.kt +22 -0
- package/android/src/main/kotlin/com/hybrid/baidu/location/CPBaiduLocationPlugin.kt +225 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +294 -0
- package/dist/esm/definitions.d.ts +163 -0
- package/dist/esm/definitions.js +24 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +69 -0
- package/dist/esm/web.js +133 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +170 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +173 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/CPBaiduLocationPlugin/CPBaiduLocation.swift +646 -0
- package/ios/Sources/CPBaiduLocationPlugin/CPBaiduLocationConfig.swift +38 -0
- package/ios/Sources/CPBaiduLocationPlugin/CPBaiduLocationPlugin.swift +167 -0
- package/package.json +82 -0
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 百度地图定位插件Web端实现
|
|
3
|
+
*/
|
|
4
|
+
import { WebPlugin } from '@capacitor/core';
|
|
5
|
+
import { CoordinateType } from './definitions';
|
|
6
|
+
/**
|
|
7
|
+
* 百度地图定位插件Web端实现类
|
|
8
|
+
*/
|
|
9
|
+
export class CPBaiduLocationWeb extends WebPlugin {
|
|
10
|
+
/**
|
|
11
|
+
* 获取当前位置信息
|
|
12
|
+
* @param _options 定位参数选项,包含needAddress和needLocationDescribe字段
|
|
13
|
+
* - needAddress: 是否需要地址信息(Web端暂不支持)
|
|
14
|
+
* - needLocationDescribe: 是否需要位置描述(Web端暂不支持)
|
|
15
|
+
* @returns 定位结果,包含经纬度、精度等信息
|
|
16
|
+
*/
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18
|
+
async getCurrentPosition(_options) {
|
|
19
|
+
return new Promise((resolve) => {
|
|
20
|
+
// 检查浏览器是否支持地理定位API
|
|
21
|
+
if (!navigator.geolocation) {
|
|
22
|
+
resolve({
|
|
23
|
+
latitude: 0,
|
|
24
|
+
longitude: 0,
|
|
25
|
+
errorCode: -1,
|
|
26
|
+
errorMessage: 'Geolocation is not supported by your browser',
|
|
27
|
+
});
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// 使用浏览器内置的地理定位API获取位置
|
|
31
|
+
navigator.geolocation.getCurrentPosition(
|
|
32
|
+
// 定位成功回调
|
|
33
|
+
(position) => {
|
|
34
|
+
// 构建定位结果对象
|
|
35
|
+
const result = {
|
|
36
|
+
latitude: position.coords.latitude, // 纬度
|
|
37
|
+
longitude: position.coords.longitude, // 经度
|
|
38
|
+
accuracy: position.coords.accuracy, // 定位精度(米)
|
|
39
|
+
};
|
|
40
|
+
resolve(result);
|
|
41
|
+
},
|
|
42
|
+
// 定位失败回调
|
|
43
|
+
(error) => {
|
|
44
|
+
// 构建错误结果对象
|
|
45
|
+
resolve({
|
|
46
|
+
latitude: 0,
|
|
47
|
+
longitude: 0,
|
|
48
|
+
errorCode: error.code, // 错误码
|
|
49
|
+
errorMessage: error.message, // 错误信息
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
// 定位选项配置
|
|
53
|
+
{
|
|
54
|
+
enableHighAccuracy: true, // 启用高精度定位
|
|
55
|
+
timeout: 5000, // 超时时间5秒
|
|
56
|
+
maximumAge: 0, // 不使用缓存的位置数据
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 检查定位权限
|
|
62
|
+
* @returns 权限状态
|
|
63
|
+
*/
|
|
64
|
+
async checkPermission() {
|
|
65
|
+
// Web端使用navigator.permissions API检查权限
|
|
66
|
+
if (navigator.permissions) {
|
|
67
|
+
try {
|
|
68
|
+
const permissionStatus = await navigator.permissions.query({ name: 'geolocation' });
|
|
69
|
+
return { granted: permissionStatus.state === 'granted' };
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.error('Error checking permission:', error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// 不支持permissions API时返回默认值
|
|
76
|
+
return { granted: true };
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 请求定位权限
|
|
80
|
+
* @returns 权限请求结果
|
|
81
|
+
*/
|
|
82
|
+
async requestPermission() {
|
|
83
|
+
// Web端通过尝试获取位置来触发权限请求
|
|
84
|
+
return new Promise((resolve) => {
|
|
85
|
+
navigator.geolocation.getCurrentPosition(() => resolve({ granted: true }), () => resolve({ granted: false }), { timeout: 1000 });
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 设置百度地图AK
|
|
90
|
+
* @param options 包含ak属性的对象,可选
|
|
91
|
+
* @returns 设置结果
|
|
92
|
+
*/
|
|
93
|
+
async setAK(options) {
|
|
94
|
+
const ak = options === null || options === void 0 ? void 0 : options.ak;
|
|
95
|
+
console.log('web setAK?', ak);
|
|
96
|
+
return { success: true };
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 检查AK验证状态
|
|
100
|
+
* @returns AK验证状态
|
|
101
|
+
*/
|
|
102
|
+
async checkAKValidation() {
|
|
103
|
+
// Web端简单实现,检查是否已设置AK
|
|
104
|
+
const ak = localStorage.getItem('baiduLocationAK');
|
|
105
|
+
if (ak && ak.length > 0) {
|
|
106
|
+
return { valid: true };
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
valid: false,
|
|
110
|
+
errorMessage: 'AK not set',
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* 设置坐标类型
|
|
115
|
+
* @param options 包含type属性的对象
|
|
116
|
+
* @returns 设置结果
|
|
117
|
+
*/
|
|
118
|
+
async setCoordinateType(options) {
|
|
119
|
+
// Web端简单实现,保存到localStorage
|
|
120
|
+
localStorage.setItem('baiduLocationCoordinateType', options.type);
|
|
121
|
+
return { success: true };
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* 获取当前坐标类型
|
|
125
|
+
* @returns 当前坐标类型
|
|
126
|
+
*/
|
|
127
|
+
async getCoordinateType() {
|
|
128
|
+
// Web端简单实现,从localStorage读取
|
|
129
|
+
const type = localStorage.getItem('baiduLocationCoordinateType') || CoordinateType.BD09LL;
|
|
130
|
+
return { type };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,SAAS;IAG7C;;;;;;OAMG;IACH,6DAA6D;IAC7D,KAAK,CAAC,kBAAkB,CAAC,QAA0B;QAC/C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC3B,mBAAmB;YACnB,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;gBACzB,OAAO,CAAC;oBACJ,QAAQ,EAAE,CAAC;oBACX,SAAS,EAAE,CAAC;oBACZ,SAAS,EAAE,CAAC,CAAC;oBACb,YAAY,EAAE,8CAA8C;iBAC/D,CAAC,CAAC;gBACH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AAI,EAAE,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,iBAAiB;QACnB,2BAA2B;QAC3B,MAAM,IAAI,GAAI,YAAY,CAAC,OAAO,CAAC,6BAA6B,CAAoB,IAAI,cAAc,CAAC,MAAM,CAAC;QAC9G,OAAO,EAAE,IAAI,EAAE,CAAC;IACpB,CAAC;CACJ","sourcesContent":["/**\n * 百度地图定位插件Web端实现\n */\nimport { WebPlugin } from '@capacitor/core';\n\nimport { CoordinateType } from './definitions';\nimport type { CPBaiduLocationPlugin, PositionOptions, PositionResult } from './definitions';\n\n/**\n * 百度地图定位插件Web端实现类\n */\nexport class CPBaiduLocationWeb extends WebPlugin implements CPBaiduLocationPlugin {\n\n\n /**\n * 获取当前位置信息\n * @param _options 定位参数选项,包含needAddress和needLocationDescribe字段\n * - needAddress: 是否需要地址信息(Web端暂不支持)\n * - needLocationDescribe: 是否需要位置描述(Web端暂不支持)\n * @returns 定位结果,包含经纬度、精度等信息\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async getCurrentPosition(_options?: PositionOptions): Promise<PositionResult> {\n return new Promise((resolve) => {\n // 检查浏览器是否支持地理定位API\n if (!navigator.geolocation) {\n resolve({\n latitude: 0,\n longitude: 0,\n errorCode: -1,\n errorMessage: 'Geolocation is not supported by your browser',\n });\n return;\n }\n\n // 使用浏览器内置的地理定位API获取位置\n navigator.geolocation.getCurrentPosition(\n // 定位成功回调\n (position) => {\n // 构建定位结果对象\n const result: PositionResult = {\n latitude: position.coords.latitude, // 纬度\n longitude: position.coords.longitude, // 经度\n accuracy: position.coords.accuracy, // 定位精度(米)\n };\n resolve(result);\n },\n // 定位失败回调\n (error) => {\n // 构建错误结果对象\n resolve({\n latitude: 0,\n longitude: 0,\n errorCode: error.code, // 错误码\n errorMessage: error.message, // 错误信息\n });\n },\n // 定位选项配置\n {\n enableHighAccuracy: true, // 启用高精度定位\n timeout: 5000, // 超时时间5秒\n maximumAge: 0, // 不使用缓存的位置数据\n },\n );\n });\n }\n\n /**\n * 检查定位权限\n * @returns 权限状态\n */\n async checkPermission(): Promise<{ granted: boolean }> {\n // Web端使用navigator.permissions API检查权限\n if (navigator.permissions) {\n try {\n const permissionStatus = await navigator.permissions.query({ name: 'geolocation' });\n return { granted: permissionStatus.state === 'granted' };\n } catch (error) {\n console.error('Error checking permission:', error);\n }\n }\n // 不支持permissions API时返回默认值\n return { granted: true };\n }\n\n /**\n * 请求定位权限\n * @returns 权限请求结果\n */\n async requestPermission(): Promise<{ granted: boolean }> {\n // Web端通过尝试获取位置来触发权限请求\n return new Promise((resolve) => {\n navigator.geolocation.getCurrentPosition(\n () => resolve({ granted: true }),\n () => resolve({ granted: false }),\n { timeout: 1000 },\n );\n });\n }\n\n /**\n * 设置百度地图AK\n * @param options 包含ak属性的对象,可选\n * @returns 设置结果\n */\n async setAK(options?: { ak: string }): Promise<{ success: boolean; errorMessage?: string }> {\n const ak = options?.ak;\n console.log('web setAK?', ak);\n return { success: true };\n }\n\n /**\n * 检查AK验证状态\n * @returns AK验证状态\n */\n async checkAKValidation(): Promise<{ valid: boolean; errorMessage?: string }> {\n // Web端简单实现,检查是否已设置AK\n const ak = localStorage.getItem('baiduLocationAK');\n if (ak && ak.length > 0) {\n return { valid: true };\n }\n return {\n valid: false,\n errorMessage: 'AK not set',\n };\n }\n\n /**\n * 设置坐标类型\n * @param options 包含type属性的对象\n * @returns 设置结果\n */\n async setCoordinateType(options: { type: CoordinateType }): Promise<{ success: boolean }> {\n // Web端简单实现,保存到localStorage\n localStorage.setItem('baiduLocationCoordinateType', options.type);\n return { success: true };\n }\n\n /**\n * 获取当前坐标类型\n * @returns 当前坐标类型\n */\n async getCoordinateType(): Promise<{ type: CoordinateType }> {\n // Web端简单实现,从localStorage读取\n const type = (localStorage.getItem('baiduLocationCoordinateType') as CoordinateType) || CoordinateType.BD09LL;\n return { type };\n }\n}\n"]}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
/// <reference types="@capacitor/cli" />
|
|
6
|
+
/**
|
|
7
|
+
* 坐标类型枚举
|
|
8
|
+
*/
|
|
9
|
+
exports.CoordinateType = void 0;
|
|
10
|
+
(function (CoordinateType) {
|
|
11
|
+
/**
|
|
12
|
+
* 百度经纬度坐标
|
|
13
|
+
*/
|
|
14
|
+
CoordinateType["BD09LL"] = "BD09LL";
|
|
15
|
+
/**
|
|
16
|
+
* 百度墨卡托米制坐标
|
|
17
|
+
*/
|
|
18
|
+
CoordinateType["BD09MC"] = "BD09MC";
|
|
19
|
+
/**
|
|
20
|
+
* 国测局坐标
|
|
21
|
+
*/
|
|
22
|
+
CoordinateType["GCJ02"] = "GCJ02";
|
|
23
|
+
/**
|
|
24
|
+
* WGS84坐标
|
|
25
|
+
*/
|
|
26
|
+
CoordinateType["WGS84"] = "WGS84";
|
|
27
|
+
})(exports.CoordinateType || (exports.CoordinateType = {}));
|
|
28
|
+
|
|
29
|
+
const CPBaiduLocation = core.registerPlugin('CPBaiduLocation', {
|
|
30
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CPBaiduLocationWeb()),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 百度地图定位插件Web端实现
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* 百度地图定位插件Web端实现类
|
|
38
|
+
*/
|
|
39
|
+
class CPBaiduLocationWeb extends core.WebPlugin {
|
|
40
|
+
/**
|
|
41
|
+
* 获取当前位置信息
|
|
42
|
+
* @param _options 定位参数选项,包含needAddress和needLocationDescribe字段
|
|
43
|
+
* - needAddress: 是否需要地址信息(Web端暂不支持)
|
|
44
|
+
* - needLocationDescribe: 是否需要位置描述(Web端暂不支持)
|
|
45
|
+
* @returns 定位结果,包含经纬度、精度等信息
|
|
46
|
+
*/
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
48
|
+
async getCurrentPosition(_options) {
|
|
49
|
+
return new Promise((resolve) => {
|
|
50
|
+
// 检查浏览器是否支持地理定位API
|
|
51
|
+
if (!navigator.geolocation) {
|
|
52
|
+
resolve({
|
|
53
|
+
latitude: 0,
|
|
54
|
+
longitude: 0,
|
|
55
|
+
errorCode: -1,
|
|
56
|
+
errorMessage: 'Geolocation is not supported by your browser',
|
|
57
|
+
});
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// 使用浏览器内置的地理定位API获取位置
|
|
61
|
+
navigator.geolocation.getCurrentPosition(
|
|
62
|
+
// 定位成功回调
|
|
63
|
+
(position) => {
|
|
64
|
+
// 构建定位结果对象
|
|
65
|
+
const result = {
|
|
66
|
+
latitude: position.coords.latitude, // 纬度
|
|
67
|
+
longitude: position.coords.longitude, // 经度
|
|
68
|
+
accuracy: position.coords.accuracy, // 定位精度(米)
|
|
69
|
+
};
|
|
70
|
+
resolve(result);
|
|
71
|
+
},
|
|
72
|
+
// 定位失败回调
|
|
73
|
+
(error) => {
|
|
74
|
+
// 构建错误结果对象
|
|
75
|
+
resolve({
|
|
76
|
+
latitude: 0,
|
|
77
|
+
longitude: 0,
|
|
78
|
+
errorCode: error.code, // 错误码
|
|
79
|
+
errorMessage: error.message, // 错误信息
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
// 定位选项配置
|
|
83
|
+
{
|
|
84
|
+
enableHighAccuracy: true, // 启用高精度定位
|
|
85
|
+
timeout: 5000, // 超时时间5秒
|
|
86
|
+
maximumAge: 0, // 不使用缓存的位置数据
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 检查定位权限
|
|
92
|
+
* @returns 权限状态
|
|
93
|
+
*/
|
|
94
|
+
async checkPermission() {
|
|
95
|
+
// Web端使用navigator.permissions API检查权限
|
|
96
|
+
if (navigator.permissions) {
|
|
97
|
+
try {
|
|
98
|
+
const permissionStatus = await navigator.permissions.query({ name: 'geolocation' });
|
|
99
|
+
return { granted: permissionStatus.state === 'granted' };
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
console.error('Error checking permission:', error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// 不支持permissions API时返回默认值
|
|
106
|
+
return { granted: true };
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 请求定位权限
|
|
110
|
+
* @returns 权限请求结果
|
|
111
|
+
*/
|
|
112
|
+
async requestPermission() {
|
|
113
|
+
// Web端通过尝试获取位置来触发权限请求
|
|
114
|
+
return new Promise((resolve) => {
|
|
115
|
+
navigator.geolocation.getCurrentPosition(() => resolve({ granted: true }), () => resolve({ granted: false }), { timeout: 1000 });
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* 设置百度地图AK
|
|
120
|
+
* @param options 包含ak属性的对象,可选
|
|
121
|
+
* @returns 设置结果
|
|
122
|
+
*/
|
|
123
|
+
async setAK(options) {
|
|
124
|
+
const ak = options === null || options === void 0 ? void 0 : options.ak;
|
|
125
|
+
console.log('web setAK?', ak);
|
|
126
|
+
return { success: true };
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 检查AK验证状态
|
|
130
|
+
* @returns AK验证状态
|
|
131
|
+
*/
|
|
132
|
+
async checkAKValidation() {
|
|
133
|
+
// Web端简单实现,检查是否已设置AK
|
|
134
|
+
const ak = localStorage.getItem('baiduLocationAK');
|
|
135
|
+
if (ak && ak.length > 0) {
|
|
136
|
+
return { valid: true };
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
valid: false,
|
|
140
|
+
errorMessage: 'AK not set',
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* 设置坐标类型
|
|
145
|
+
* @param options 包含type属性的对象
|
|
146
|
+
* @returns 设置结果
|
|
147
|
+
*/
|
|
148
|
+
async setCoordinateType(options) {
|
|
149
|
+
// Web端简单实现,保存到localStorage
|
|
150
|
+
localStorage.setItem('baiduLocationCoordinateType', options.type);
|
|
151
|
+
return { success: true };
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* 获取当前坐标类型
|
|
155
|
+
* @returns 当前坐标类型
|
|
156
|
+
*/
|
|
157
|
+
async getCoordinateType() {
|
|
158
|
+
// Web端简单实现,从localStorage读取
|
|
159
|
+
const type = localStorage.getItem('baiduLocationCoordinateType') || exports.CoordinateType.BD09LL;
|
|
160
|
+
return { type };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
165
|
+
__proto__: null,
|
|
166
|
+
CPBaiduLocationWeb: CPBaiduLocationWeb
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
exports.CPBaiduLocation = CPBaiduLocation;
|
|
170
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/// <reference types=\"@capacitor/cli\" />\n/**\n * 坐标类型枚举\n */\nexport var CoordinateType;\n(function (CoordinateType) {\n /**\n * 百度经纬度坐标\n */\n CoordinateType[\"BD09LL\"] = \"BD09LL\";\n /**\n * 百度墨卡托米制坐标\n */\n CoordinateType[\"BD09MC\"] = \"BD09MC\";\n /**\n * 国测局坐标\n */\n CoordinateType[\"GCJ02\"] = \"GCJ02\";\n /**\n * WGS84坐标\n */\n CoordinateType[\"WGS84\"] = \"WGS84\";\n})(CoordinateType || (CoordinateType = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst CPBaiduLocation = registerPlugin('CPBaiduLocation', {\n web: () => import('./web').then((m) => new m.CPBaiduLocationWeb()),\n});\nexport * from './definitions';\nexport { CPBaiduLocation };\n//# sourceMappingURL=index.js.map","/**\n * 百度地图定位插件Web端实现\n */\nimport { WebPlugin } from '@capacitor/core';\nimport { CoordinateType } from './definitions';\n/**\n * 百度地图定位插件Web端实现类\n */\nexport class CPBaiduLocationWeb extends WebPlugin {\n /**\n * 获取当前位置信息\n * @param _options 定位参数选项,包含needAddress和needLocationDescribe字段\n * - needAddress: 是否需要地址信息(Web端暂不支持)\n * - needLocationDescribe: 是否需要位置描述(Web端暂不支持)\n * @returns 定位结果,包含经纬度、精度等信息\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async getCurrentPosition(_options) {\n return new Promise((resolve) => {\n // 检查浏览器是否支持地理定位API\n if (!navigator.geolocation) {\n resolve({\n latitude: 0,\n longitude: 0,\n errorCode: -1,\n errorMessage: 'Geolocation is not supported by your browser',\n });\n return;\n }\n // 使用浏览器内置的地理定位API获取位置\n navigator.geolocation.getCurrentPosition(\n // 定位成功回调\n (position) => {\n // 构建定位结果对象\n const result = {\n latitude: position.coords.latitude, // 纬度\n longitude: position.coords.longitude, // 经度\n accuracy: position.coords.accuracy, // 定位精度(米)\n };\n resolve(result);\n }, \n // 定位失败回调\n (error) => {\n // 构建错误结果对象\n resolve({\n latitude: 0,\n longitude: 0,\n errorCode: error.code, // 错误码\n errorMessage: error.message, // 错误信息\n });\n }, \n // 定位选项配置\n {\n enableHighAccuracy: true, // 启用高精度定位\n timeout: 5000, // 超时时间5秒\n maximumAge: 0, // 不使用缓存的位置数据\n });\n });\n }\n /**\n * 检查定位权限\n * @returns 权限状态\n */\n async checkPermission() {\n // Web端使用navigator.permissions API检查权限\n if (navigator.permissions) {\n try {\n const permissionStatus = await navigator.permissions.query({ name: 'geolocation' });\n return { granted: permissionStatus.state === 'granted' };\n }\n catch (error) {\n console.error('Error checking permission:', error);\n }\n }\n // 不支持permissions API时返回默认值\n return { granted: true };\n }\n /**\n * 请求定位权限\n * @returns 权限请求结果\n */\n async requestPermission() {\n // Web端通过尝试获取位置来触发权限请求\n return new Promise((resolve) => {\n navigator.geolocation.getCurrentPosition(() => resolve({ granted: true }), () => resolve({ granted: false }), { timeout: 1000 });\n });\n }\n /**\n * 设置百度地图AK\n * @param options 包含ak属性的对象,可选\n * @returns 设置结果\n */\n async setAK(options) {\n const ak = options === null || options === void 0 ? void 0 : options.ak;\n console.log('web setAK?', ak);\n return { success: true };\n }\n /**\n * 检查AK验证状态\n * @returns AK验证状态\n */\n async checkAKValidation() {\n // Web端简单实现,检查是否已设置AK\n const ak = localStorage.getItem('baiduLocationAK');\n if (ak && ak.length > 0) {\n return { valid: true };\n }\n return {\n valid: false,\n errorMessage: 'AK not set',\n };\n }\n /**\n * 设置坐标类型\n * @param options 包含type属性的对象\n * @returns 设置结果\n */\n async setCoordinateType(options) {\n // Web端简单实现,保存到localStorage\n localStorage.setItem('baiduLocationCoordinateType', options.type);\n return { success: true };\n }\n /**\n * 获取当前坐标类型\n * @returns 当前坐标类型\n */\n async getCoordinateType() {\n // Web端简单实现,从localStorage读取\n const type = localStorage.getItem('baiduLocationCoordinateType') || CoordinateType.BD09LL;\n return { type };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["CoordinateType","registerPlugin","WebPlugin"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACWA;AACX,CAAC,UAAU,cAAc,EAAE;AAC3B;AACA;AACA;AACA,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,QAAQ;AACvC;AACA;AACA;AACA,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,QAAQ;AACvC;AACA;AACA;AACA,IAAI,cAAc,CAAC,OAAO,CAAC,GAAG,OAAO;AACrC;AACA;AACA;AACA,IAAI,cAAc,CAAC,OAAO,CAAC,GAAG,OAAO;AACrC,CAAC,EAAEA,sBAAc,KAAKA,sBAAc,GAAG,EAAE,CAAC,CAAC;;ACrBtC,MAAC,eAAe,GAAGC,mBAAc,CAAC,iBAAiB,EAAE;AAC1D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,kBAAkB,EAAE,CAAC;AACtE,CAAC;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,IAAI,MAAM,iBAAiB,GAAG;AAC9B;AACA,QAAQ,MAAM,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,iBAAiB,CAAC;AAC1D,QAAQ,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE;AACjC,YAAY,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE;AAClC,QAAQ;AACR,QAAQ,OAAO;AACf,YAAY,KAAK,EAAE,KAAK;AACxB,YAAY,YAAY,EAAE,YAAY;AACtC,SAAS;AACT,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,iBAAiB,CAAC,OAAO,EAAE;AACrC;AACA,QAAQ,YAAY,CAAC,OAAO,CAAC,6BAA6B,EAAE,OAAO,CAAC,IAAI,CAAC;AACzE,QAAQ,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE;AAChC,IAAI;AACJ;AACA;AACA;AACA;AACA,IAAI,MAAM,iBAAiB,GAAG;AAC9B;AACA,QAAQ,MAAM,IAAI,GAAG,YAAY,CAAC,OAAO,CAAC,6BAA6B,CAAC,IAAIF,sBAAc,CAAC,MAAM;AACjG,QAAQ,OAAO,EAAE,IAAI,EAAE;AACvB,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
var capacitorCPBaiduLocation = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/// <reference types="@capacitor/cli" />
|
|
5
|
+
/**
|
|
6
|
+
* 坐标类型枚举
|
|
7
|
+
*/
|
|
8
|
+
exports.CoordinateType = void 0;
|
|
9
|
+
(function (CoordinateType) {
|
|
10
|
+
/**
|
|
11
|
+
* 百度经纬度坐标
|
|
12
|
+
*/
|
|
13
|
+
CoordinateType["BD09LL"] = "BD09LL";
|
|
14
|
+
/**
|
|
15
|
+
* 百度墨卡托米制坐标
|
|
16
|
+
*/
|
|
17
|
+
CoordinateType["BD09MC"] = "BD09MC";
|
|
18
|
+
/**
|
|
19
|
+
* 国测局坐标
|
|
20
|
+
*/
|
|
21
|
+
CoordinateType["GCJ02"] = "GCJ02";
|
|
22
|
+
/**
|
|
23
|
+
* WGS84坐标
|
|
24
|
+
*/
|
|
25
|
+
CoordinateType["WGS84"] = "WGS84";
|
|
26
|
+
})(exports.CoordinateType || (exports.CoordinateType = {}));
|
|
27
|
+
|
|
28
|
+
const CPBaiduLocation = core.registerPlugin('CPBaiduLocation', {
|
|
29
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CPBaiduLocationWeb()),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 百度地图定位插件Web端实现
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* 百度地图定位插件Web端实现类
|
|
37
|
+
*/
|
|
38
|
+
class CPBaiduLocationWeb extends core.WebPlugin {
|
|
39
|
+
/**
|
|
40
|
+
* 获取当前位置信息
|
|
41
|
+
* @param _options 定位参数选项,包含needAddress和needLocationDescribe字段
|
|
42
|
+
* - needAddress: 是否需要地址信息(Web端暂不支持)
|
|
43
|
+
* - needLocationDescribe: 是否需要位置描述(Web端暂不支持)
|
|
44
|
+
* @returns 定位结果,包含经纬度、精度等信息
|
|
45
|
+
*/
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
47
|
+
async getCurrentPosition(_options) {
|
|
48
|
+
return new Promise((resolve) => {
|
|
49
|
+
// 检查浏览器是否支持地理定位API
|
|
50
|
+
if (!navigator.geolocation) {
|
|
51
|
+
resolve({
|
|
52
|
+
latitude: 0,
|
|
53
|
+
longitude: 0,
|
|
54
|
+
errorCode: -1,
|
|
55
|
+
errorMessage: 'Geolocation is not supported by your browser',
|
|
56
|
+
});
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// 使用浏览器内置的地理定位API获取位置
|
|
60
|
+
navigator.geolocation.getCurrentPosition(
|
|
61
|
+
// 定位成功回调
|
|
62
|
+
(position) => {
|
|
63
|
+
// 构建定位结果对象
|
|
64
|
+
const result = {
|
|
65
|
+
latitude: position.coords.latitude, // 纬度
|
|
66
|
+
longitude: position.coords.longitude, // 经度
|
|
67
|
+
accuracy: position.coords.accuracy, // 定位精度(米)
|
|
68
|
+
};
|
|
69
|
+
resolve(result);
|
|
70
|
+
},
|
|
71
|
+
// 定位失败回调
|
|
72
|
+
(error) => {
|
|
73
|
+
// 构建错误结果对象
|
|
74
|
+
resolve({
|
|
75
|
+
latitude: 0,
|
|
76
|
+
longitude: 0,
|
|
77
|
+
errorCode: error.code, // 错误码
|
|
78
|
+
errorMessage: error.message, // 错误信息
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
// 定位选项配置
|
|
82
|
+
{
|
|
83
|
+
enableHighAccuracy: true, // 启用高精度定位
|
|
84
|
+
timeout: 5000, // 超时时间5秒
|
|
85
|
+
maximumAge: 0, // 不使用缓存的位置数据
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 检查定位权限
|
|
91
|
+
* @returns 权限状态
|
|
92
|
+
*/
|
|
93
|
+
async checkPermission() {
|
|
94
|
+
// Web端使用navigator.permissions API检查权限
|
|
95
|
+
if (navigator.permissions) {
|
|
96
|
+
try {
|
|
97
|
+
const permissionStatus = await navigator.permissions.query({ name: 'geolocation' });
|
|
98
|
+
return { granted: permissionStatus.state === 'granted' };
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
console.error('Error checking permission:', error);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// 不支持permissions API时返回默认值
|
|
105
|
+
return { granted: true };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 请求定位权限
|
|
109
|
+
* @returns 权限请求结果
|
|
110
|
+
*/
|
|
111
|
+
async requestPermission() {
|
|
112
|
+
// Web端通过尝试获取位置来触发权限请求
|
|
113
|
+
return new Promise((resolve) => {
|
|
114
|
+
navigator.geolocation.getCurrentPosition(() => resolve({ granted: true }), () => resolve({ granted: false }), { timeout: 1000 });
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 设置百度地图AK
|
|
119
|
+
* @param options 包含ak属性的对象,可选
|
|
120
|
+
* @returns 设置结果
|
|
121
|
+
*/
|
|
122
|
+
async setAK(options) {
|
|
123
|
+
const ak = options === null || options === void 0 ? void 0 : options.ak;
|
|
124
|
+
console.log('web setAK?', ak);
|
|
125
|
+
return { success: true };
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 检查AK验证状态
|
|
129
|
+
* @returns AK验证状态
|
|
130
|
+
*/
|
|
131
|
+
async checkAKValidation() {
|
|
132
|
+
// Web端简单实现,检查是否已设置AK
|
|
133
|
+
const ak = localStorage.getItem('baiduLocationAK');
|
|
134
|
+
if (ak && ak.length > 0) {
|
|
135
|
+
return { valid: true };
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
valid: false,
|
|
139
|
+
errorMessage: 'AK not set',
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* 设置坐标类型
|
|
144
|
+
* @param options 包含type属性的对象
|
|
145
|
+
* @returns 设置结果
|
|
146
|
+
*/
|
|
147
|
+
async setCoordinateType(options) {
|
|
148
|
+
// Web端简单实现,保存到localStorage
|
|
149
|
+
localStorage.setItem('baiduLocationCoordinateType', options.type);
|
|
150
|
+
return { success: true };
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 获取当前坐标类型
|
|
154
|
+
* @returns 当前坐标类型
|
|
155
|
+
*/
|
|
156
|
+
async getCoordinateType() {
|
|
157
|
+
// Web端简单实现,从localStorage读取
|
|
158
|
+
const type = localStorage.getItem('baiduLocationCoordinateType') || exports.CoordinateType.BD09LL;
|
|
159
|
+
return { type };
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
164
|
+
__proto__: null,
|
|
165
|
+
CPBaiduLocationWeb: CPBaiduLocationWeb
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
exports.CPBaiduLocation = CPBaiduLocation;
|
|
169
|
+
|
|
170
|
+
return exports;
|
|
171
|
+
|
|
172
|
+
})({}, capacitorExports);
|
|
173
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/// <reference types=\"@capacitor/cli\" />\n/**\n * 坐标类型枚举\n */\nexport var CoordinateType;\n(function (CoordinateType) {\n /**\n * 百度经纬度坐标\n */\n CoordinateType[\"BD09LL\"] = \"BD09LL\";\n /**\n * 百度墨卡托米制坐标\n */\n CoordinateType[\"BD09MC\"] = \"BD09MC\";\n /**\n * 国测局坐标\n */\n CoordinateType[\"GCJ02\"] = \"GCJ02\";\n /**\n * WGS84坐标\n */\n CoordinateType[\"WGS84\"] = \"WGS84\";\n})(CoordinateType || (CoordinateType = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst CPBaiduLocation = registerPlugin('CPBaiduLocation', {\n web: () => import('./web').then((m) => new m.CPBaiduLocationWeb()),\n});\nexport * from './definitions';\nexport { CPBaiduLocation };\n//# sourceMappingURL=index.js.map","/**\n * 百度地图定位插件Web端实现\n */\nimport { WebPlugin } from '@capacitor/core';\nimport { CoordinateType } from './definitions';\n/**\n * 百度地图定位插件Web端实现类\n */\nexport class CPBaiduLocationWeb extends WebPlugin {\n /**\n * 获取当前位置信息\n * @param _options 定位参数选项,包含needAddress和needLocationDescribe字段\n * - needAddress: 是否需要地址信息(Web端暂不支持)\n * - needLocationDescribe: 是否需要位置描述(Web端暂不支持)\n * @returns 定位结果,包含经纬度、精度等信息\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async getCurrentPosition(_options) {\n return new Promise((resolve) => {\n // 检查浏览器是否支持地理定位API\n if (!navigator.geolocation) {\n resolve({\n latitude: 0,\n longitude: 0,\n errorCode: -1,\n errorMessage: 'Geolocation is not supported by your browser',\n });\n return;\n }\n // 使用浏览器内置的地理定位API获取位置\n navigator.geolocation.getCurrentPosition(\n // 定位成功回调\n (position) => {\n // 构建定位结果对象\n const result = {\n latitude: position.coords.latitude, // 纬度\n longitude: position.coords.longitude, // 经度\n accuracy: position.coords.accuracy, // 定位精度(米)\n };\n resolve(result);\n }, \n // 定位失败回调\n (error) => {\n // 构建错误结果对象\n resolve({\n latitude: 0,\n longitude: 0,\n errorCode: error.code, // 错误码\n errorMessage: error.message, // 错误信息\n });\n }, \n // 定位选项配置\n {\n enableHighAccuracy: true, // 启用高精度定位\n timeout: 5000, // 超时时间5秒\n maximumAge: 0, // 不使用缓存的位置数据\n });\n });\n }\n /**\n * 检查定位权限\n * @returns 权限状态\n */\n async checkPermission() {\n // Web端使用navigator.permissions API检查权限\n if (navigator.permissions) {\n try {\n const permissionStatus = await navigator.permissions.query({ name: 'geolocation' });\n return { granted: permissionStatus.state === 'granted' };\n }\n catch (error) {\n console.error('Error checking permission:', error);\n }\n }\n // 不支持permissions API时返回默认值\n return { granted: true };\n }\n /**\n * 请求定位权限\n * @returns 权限请求结果\n */\n async requestPermission() {\n // Web端通过尝试获取位置来触发权限请求\n return new Promise((resolve) => {\n navigator.geolocation.getCurrentPosition(() => resolve({ granted: true }), () => resolve({ granted: false }), { timeout: 1000 });\n });\n }\n /**\n * 设置百度地图AK\n * @param options 包含ak属性的对象,可选\n * @returns 设置结果\n */\n async setAK(options) {\n const ak = options === null || options === void 0 ? void 0 : options.ak;\n console.log('web setAK?', ak);\n return { success: true };\n }\n /**\n * 检查AK验证状态\n * @returns AK验证状态\n */\n async checkAKValidation() {\n // Web端简单实现,检查是否已设置AK\n const ak = localStorage.getItem('baiduLocationAK');\n if (ak && ak.length > 0) {\n return { valid: true };\n }\n return {\n valid: false,\n errorMessage: 'AK not set',\n };\n }\n /**\n * 设置坐标类型\n * @param options 包含type属性的对象\n * @returns 设置结果\n */\n async setCoordinateType(options) {\n // Web端简单实现,保存到localStorage\n localStorage.setItem('baiduLocationCoordinateType', options.type);\n return { success: true };\n }\n /**\n * 获取当前坐标类型\n * @returns 当前坐标类型\n */\n async getCoordinateType() {\n // Web端简单实现,从localStorage读取\n const type = localStorage.getItem('baiduLocationCoordinateType') || CoordinateType.BD09LL;\n return { type };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["CoordinateType","registerPlugin","WebPlugin"],"mappings":";;;IAAA;IACA;IACA;IACA;AACWA;IACX,CAAC,UAAU,cAAc,EAAE;IAC3B;IACA;IACA;IACA,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,QAAQ;IACvC;IACA;IACA;IACA,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,QAAQ;IACvC;IACA;IACA;IACA,IAAI,cAAc,CAAC,OAAO,CAAC,GAAG,OAAO;IACrC;IACA;IACA;IACA,IAAI,cAAc,CAAC,OAAO,CAAC,GAAG,OAAO;IACrC,CAAC,EAAEA,sBAAc,KAAKA,sBAAc,GAAG,EAAE,CAAC,CAAC;;ACrBtC,UAAC,eAAe,GAAGC,mBAAc,CAAC,iBAAiB,EAAE;IAC1D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,kBAAkB,EAAE,CAAC;IACtE,CAAC;;ICHD;IACA;IACA;IAGA;IACA;IACA;IACO,MAAM,kBAAkB,SAASC,cAAS,CAAC;IAClD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,IAAI,MAAM,kBAAkB,CAAC,QAAQ,EAAE;IACvC,QAAQ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK;IACxC;IACA,YAAY,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;IACxC,gBAAgB,OAAO,CAAC;IACxB,oBAAoB,QAAQ,EAAE,CAAC;IAC/B,oBA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