Forráskód Böngészése

sentry location fix

Viktoriia 7 hónapja
szülő
commit
5e5d70a19d
1 módosított fájl, 38 hozzáadás és 30 törlés
  1. 38 30
      src/screens/InAppScreens/MapScreen/index.tsx

+ 38 - 30
src/screens/InAppScreens/MapScreen/index.tsx

@@ -567,19 +567,23 @@ const MapScreen: any = ({ navigation, route }: { navigation: any; route: any })
         return;
       }
 
-      let currentLocation = await Location.getCurrentPositionAsync({
-        accuracy: Location.Accuracy.Balanced
-      });
-      setLocation(currentLocation.coords);
-
-      if (showNomads && token) {
-        updateLocation({
-          token,
-          lat: currentLocation.coords.latitude,
-          lng: currentLocation.coords.longitude
+      try {
+        let currentLocation = await Location.getCurrentPositionAsync({
+          accuracy: Location.Accuracy.Balanced
         });
+        setLocation(currentLocation.coords);
 
-        refetchUsersLocation();
+        if (showNomads && token) {
+          updateLocation({
+            token,
+            lat: currentLocation.coords.latitude,
+            lng: currentLocation.coords.longitude
+          });
+
+          refetchUsersLocation();
+        }
+      } catch (error) {
+        console.error('Error fetching user location:', error);
       }
     })();
   }, [locationSettings]);
@@ -819,29 +823,33 @@ const MapScreen: any = ({ navigation, route }: { navigation: any; route: any })
   };
 
   const getLocation = async () => {
-    let currentLocation = await Location.getCurrentPositionAsync({
-      accuracy: Location.Accuracy.Balanced
-    });
-    setLocation(currentLocation.coords);
+    try {
+      let currentLocation = await Location.getCurrentPositionAsync({
+        accuracy: Location.Accuracy.Balanced
+      });
+      setLocation(currentLocation.coords);
 
-    if (currentLocation.coords) {
-      cameraRef.current?.flyTo(
-        [currentLocation.coords.longitude, currentLocation.coords.latitude],
-        1000
-      );
-    }
+      if (currentLocation.coords) {
+        cameraRef.current?.flyTo(
+          [currentLocation.coords.longitude, currentLocation.coords.latitude],
+          1000
+        );
+      }
 
-    if (showNomads && token) {
-      updateLocation({
-        token,
-        lat: currentLocation.coords.latitude,
-        lng: currentLocation.coords.longitude
-      });
+      if (showNomads && token) {
+        updateLocation({
+          token,
+          lat: currentLocation.coords.latitude,
+          lng: currentLocation.coords.longitude
+        });
 
-      refetchUsersLocation();
-    }
+        refetchUsersLocation();
+      }
 
-    handleClosePopup();
+      handleClosePopup();
+    } catch (error) {
+      console.error('Error fetching user location:', error);
+    }
   };
 
   const handleAcceptPermission = async () => {