feat: use Capacitor Geolocation to prompt and get native location on Android

This commit is contained in:
2026-06-27 22:15:18 +07:00
parent 7f426c8e46
commit 964a72514f
5 changed files with 68 additions and 38 deletions
+5 -17
View File
@@ -14,6 +14,7 @@ import { useNotification } from '@/hooks/useNotification';
import { processImageModeration } from '../hooks/useImageModeration';
import { useTranslation } from '../hooks/useTranslation';
import { processAndResizeImage } from '../utils/imageProcessor';
import { getDeviceLocation } from '../utils/geolocation';
interface LandingPageProps {
onContinue?: () => void;
@@ -215,23 +216,10 @@ export const LandingPage: React.FC<LandingPageProps> = ({
// 2. Get current mobile/device GPS position of the user
if (finalLat === null || finalLng === null) {
try {
const pos = await Promise.race([
new Promise<GeolocationPosition | null>((resolve) => {
if (!navigator.geolocation) {
resolve(null);
} else {
navigator.geolocation.getCurrentPosition(
(p) => resolve(p),
() => resolve(null),
{ timeout: 4000, enableHighAccuracy: true }
);
}
}),
new Promise<null>((resolve) => setTimeout(() => resolve(null), 4500))
]);
if (pos && pos.coords) {
finalLat = pos.coords.latitude;
finalLng = pos.coords.longitude;
const deviceLoc = await getDeviceLocation();
if (deviceLoc) {
finalLat = deviceLoc.latitude;
finalLng = deviceLoc.longitude;
console.log('[Upload Location] Priority 2: GPS coordinates found:', finalLat, finalLng);
}
} catch (e) {