@cpzxrobot/sdk 1.1.43 → 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 +21 -0
- package/index.ts +23 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -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
|
@@ -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 {
|