feat: add device orientation permission request and integrate with location tracking
All checks were successful
Migrate supabase / migrate (push) Successful in 14s
All checks were successful
Migrate supabase / migrate (push) Successful in 14s
This commit is contained in:
@@ -127,6 +127,31 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Request device orientation permission (iOS 13+)
|
||||||
|
async function requestOrientationPermission() {
|
||||||
|
if (typeof DeviceOrientationEvent === 'undefined') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if permission request is needed (iOS 13+)
|
||||||
|
const DeviceOrientationEventTyped = DeviceOrientationEvent as typeof DeviceOrientationEvent & {
|
||||||
|
requestPermission?: () => Promise<'granted' | 'denied'>;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof DeviceOrientationEventTyped.requestPermission === 'function') {
|
||||||
|
try {
|
||||||
|
const permission = await DeviceOrientationEventTyped.requestPermission();
|
||||||
|
return permission === 'granted';
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error requesting orientation permission:', error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Permission not required on this device
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function startLocationTracking() {
|
function startLocationTracking() {
|
||||||
if (!('geolocation' in navigator)) {
|
if (!('geolocation' in navigator)) {
|
||||||
return;
|
return;
|
||||||
@@ -142,8 +167,8 @@
|
|||||||
locationError = null;
|
locationError = null;
|
||||||
locationPermission = 'granted';
|
locationPermission = 'granted';
|
||||||
|
|
||||||
// Try to get device heading if available
|
// Try to get device heading if available from GPS
|
||||||
if (position.coords.heading !== null) {
|
if (position.coords.heading !== null && position.coords.heading >= 0) {
|
||||||
heading = position.coords.heading;
|
heading = position.coords.heading;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -170,8 +195,17 @@
|
|||||||
timeout: 10000
|
timeout: 10000
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Try to use device orientation for compass heading
|
async function startOrientationTracking() {
|
||||||
|
// Request permission first
|
||||||
|
const hasPermission = await requestOrientationPermission();
|
||||||
|
if (!hasPermission) {
|
||||||
|
console.log('Orientation permission denied or not available');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start listening to orientation events
|
||||||
if (typeof DeviceOrientationEvent !== 'undefined') {
|
if (typeof DeviceOrientationEvent !== 'undefined') {
|
||||||
const hasAbsoluteOrientation = 'ondeviceorientationabsolute' in window;
|
const hasAbsoluteOrientation = 'ondeviceorientationabsolute' in window;
|
||||||
const hasOrientation = 'ondeviceorientation' in window;
|
const hasOrientation = 'ondeviceorientation' in window;
|
||||||
@@ -196,10 +230,9 @@
|
|||||||
// Initialize location tracking
|
// Initialize location tracking
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (currentStep?.type === 'location' && isCurrentActiveStep) {
|
if (currentStep?.type === 'location' && isCurrentActiveStep) {
|
||||||
checkLocationPermission().then(hasPermission => {
|
checkLocationPermission().then(() => {
|
||||||
if (hasPermission) {
|
|
||||||
startLocationTracking();
|
startLocationTracking();
|
||||||
}
|
startOrientationTracking();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user