@cpzxrobot/sdk 1.1.42 → 1.1.44
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/dist/index.js +23 -2
- package/index.ts +27 -4
- package/package.json +1 -1
- package/types.d.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -148,8 +148,8 @@ class Cpzxrobot {
|
|
|
148
148
|
this.scanQrcode = function () {
|
|
149
149
|
return platform.callHandler("app.scanQrcode");
|
|
150
150
|
};
|
|
151
|
-
this.getGeo = function () {
|
|
152
|
-
var result = platform.callHandler("app.getGeo");
|
|
151
|
+
this.getGeo = async function () {
|
|
152
|
+
var result = await platform.callHandler("app.getGeo");
|
|
153
153
|
if (result.error) {
|
|
154
154
|
throw result.error;
|
|
155
155
|
}
|
|
@@ -235,6 +235,27 @@ class Cpzxrobot {
|
|
|
235
235
|
URL.revokeObjectURL(url);
|
|
236
236
|
document.body.removeChild(a);
|
|
237
237
|
};
|
|
238
|
+
this.getGeo = async function () {
|
|
239
|
+
return new Promise((resolve, reject) => {
|
|
240
|
+
if (navigator.geolocation) {
|
|
241
|
+
navigator.geolocation.getCurrentPosition((position) => {
|
|
242
|
+
const lat = position.coords.latitude; // 获取纬度
|
|
243
|
+
const lng = position.coords.longitude; // 获取经度
|
|
244
|
+
// 完成位置获取,解析 Promise
|
|
245
|
+
resolve({ lat, lng });
|
|
246
|
+
}, (error) => {
|
|
247
|
+
console.log("获取位置信息失败:" + error.message);
|
|
248
|
+
// 位置获取失败,拒绝 Promise
|
|
249
|
+
reject(error);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
console.log("浏览器不支持获取位置信息");
|
|
254
|
+
// 浏览器不支持位置服务,拒绝 Promise
|
|
255
|
+
reject(new Error("浏览器不支持获取位置信息"));
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
};
|
|
238
259
|
}
|
|
239
260
|
}
|
|
240
261
|
isIosMiniApp(location) {
|
package/index.ts
CHANGED
|
@@ -46,10 +46,10 @@ export class Cpzxrobot {
|
|
|
46
46
|
saveBlob!: (blob: Blob, filename: string) => void;
|
|
47
47
|
scanQrcode!: () => Promise<string>;
|
|
48
48
|
vibrate!: (time?: number) => void;
|
|
49
|
-
getGeo!: () => {
|
|
49
|
+
getGeo!: () => Promise<{
|
|
50
50
|
lat: number;
|
|
51
51
|
lng: number;
|
|
52
|
-
}
|
|
52
|
+
}>;
|
|
53
53
|
assistant: AssistantGateway;
|
|
54
54
|
energy: EnergyGateway;
|
|
55
55
|
camera: CameraGateway;
|
|
@@ -185,8 +185,8 @@ export class Cpzxrobot {
|
|
|
185
185
|
this.scanQrcode = function () {
|
|
186
186
|
return platform.callHandler("app.scanQrcode");
|
|
187
187
|
}
|
|
188
|
-
this.getGeo = function () {
|
|
189
|
-
var result = platform.callHandler("app.getGeo");
|
|
188
|
+
this.getGeo = async function () {
|
|
189
|
+
var result = await platform.callHandler("app.getGeo");
|
|
190
190
|
if (result.error) {
|
|
191
191
|
throw result.error;
|
|
192
192
|
}
|
|
@@ -275,6 +275,29 @@ export class Cpzxrobot {
|
|
|
275
275
|
URL.revokeObjectURL(url);
|
|
276
276
|
document.body.removeChild(a);
|
|
277
277
|
};
|
|
278
|
+
this.getGeo = async function () {
|
|
279
|
+
return new Promise((resolve, reject) => {
|
|
280
|
+
if (navigator.geolocation) {
|
|
281
|
+
navigator.geolocation.getCurrentPosition(
|
|
282
|
+
(position) => {
|
|
283
|
+
const lat = position.coords.latitude; // 获取纬度
|
|
284
|
+
const lng = position.coords.longitude; // 获取经度
|
|
285
|
+
// 完成位置获取,解析 Promise
|
|
286
|
+
resolve({ lat, lng });
|
|
287
|
+
},
|
|
288
|
+
(error) => {
|
|
289
|
+
console.log("获取位置信息失败:" + error.message);
|
|
290
|
+
// 位置获取失败,拒绝 Promise
|
|
291
|
+
reject(error);
|
|
292
|
+
}
|
|
293
|
+
);
|
|
294
|
+
} else {
|
|
295
|
+
console.log("浏览器不支持获取位置信息");
|
|
296
|
+
// 浏览器不支持位置服务,拒绝 Promise
|
|
297
|
+
reject(new Error("浏览器不支持获取位置信息"));
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
};
|
|
278
301
|
}
|
|
279
302
|
}
|
|
280
303
|
isIosMiniApp(location: Location): boolean {
|
package/package.json
CHANGED
package/types.d.ts
CHANGED