From 77b15609b62c9bcd80fcdfd65f134a06252920b9 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期一, 14 四月 2025 17:11:21 +0800
Subject: [PATCH] 48px

---
 src/utils/brower.ts |   44 ++++++++++++++++++++++++++++++++++----------
 1 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/src/utils/brower.ts b/src/utils/brower.ts
index c4f9735..bf10a94 100644
--- a/src/utils/brower.ts
+++ b/src/utils/brower.ts
@@ -1,14 +1,38 @@
+import { currentPosition } from '../stores/chatRoom';
+
 export function getCurrentPosition() {
-	const p = new Promise<GeolocationPosition | null>((resolve, reject) => {
-		if (navigator.geolocation) {
-			navigator.geolocation.getCurrentPosition(
-				(position) => resolve(position),
-				(error) => {
-					resolve(null);
-				}
-			);
-		} else {
-			console.log('Geolocation is not supported by this browser.');
+	if (currentPosition.value) {
+		return Promise.resolve(currentPosition.value);
+	}
+	const p = new Promise<{
+		latitude: number;
+		longitude: number;
+	}>((resolve, reject) => {
+		try {
+			const geoLocation = window.plus ? plus.geolocation : navigator.geolocation;
+			if (geoLocation) {
+				geoLocation.getCurrentPosition(
+					(position) => {
+						const { latitude, longitude } = position.coords;
+						currentPosition.value = {
+							latitude,
+							longitude,
+						};
+						resolve({
+							latitude,
+							longitude,
+						});
+					},
+
+					(error) => {
+						resolve(null);
+					}
+				);
+			} else {
+				console.log('Geolocation is not supported by this browser.');
+				resolve(null);
+			}
+		} catch (error) {
 			resolve(null);
 		}
 	});

--
Gitblit v1.9.3