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
@@ -4,6 +4,7 @@ import { useNotification } from '@/hooks/useNotification';
import { useTourStore } from '@/store/useTourStore';
import { processImageModeration } from '@/hooks/useImageModeration';
import { processAndResizeImage } from '../utils/imageProcessor';
import { getDeviceLocation } from '../utils/geolocation';
interface AddPhotoModalProps {
isOpen: boolean;
@@ -38,20 +39,7 @@ export const AddPhotoModal: React.FC<AddPhotoModalProps> = ({ isOpen, onClose, t
try {
// Fetch device location once to serve as Priority 2 fallback for files without EXIF
const deviceLocation = await Promise.race([
new Promise<GeolocationPosition | null>((resolve) => {
if (!navigator.geolocation) {
resolve(null);
} else {
navigator.geolocation.getCurrentPosition(
(pos) => resolve(pos),
() => resolve(null),
{ timeout: 3500, enableHighAccuracy: true }
);
}
}),
new Promise<null>((resolve) => setTimeout(() => resolve(null), 4000))
]);
const deviceLocation = await getDeviceLocation();
const newValidPhotos: PendingPhoto[] = [];
const newValidPreviews: string[] = [];
@@ -89,9 +77,9 @@ export const AddPhotoModal: React.FC<AddPhotoModalProps> = ({ isOpen, onClose, t
let finalLng: number | null = exifLng;
// Priority 2: Device location
if ((finalLat === null || finalLng === null) && deviceLocation && deviceLocation.coords) {
finalLat = deviceLocation.coords.latitude;
finalLng = deviceLocation.coords.longitude;
if ((finalLat === null || finalLng === null) && deviceLocation) {
finalLat = deviceLocation.latitude;
finalLng = deviceLocation.longitude;
}
// Priority 3: Map view state