predikt/oracle/native/lib/location.ts
caelum0x 2b68bde5d5 Predikt: full Polymarket-style prediction market — web + mobile + on-chain + bots
Working tree is now the canonical repo. Off-chain play-money + trustless on-chain
(FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution,
mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-06 23:29:50 +03:00

42 lines
1.2 KiB
TypeScript

import * as Location from 'expo-location'
import { GPSData } from 'common/gidx/gidx'
import { MINUTE_MS } from 'common/util/time'
export const checkLocationPermission = async () => {
let { status } = await Location.getForegroundPermissionsAsync()
return status
}
export const getLocation = async () => {
const error =
'Permission to access location was denied, please enable it in settings.'
const status = await checkLocationPermission()
if (status === 'denied') {
console.log('Permission to access location was denied')
return {
error,
}
}
if (status === 'undetermined') {
let { status } = await Location.requestForegroundPermissionsAsync()
if (status !== 'granted') {
return { error }
}
}
let location = await Location.getLastKnownPositionAsync({
maxAge: 20 * MINUTE_MS,
})
if (!location) location = await Location.getCurrentPositionAsync({})
return {
Latitude: location.coords.latitude,
Longitude: location.coords.longitude,
Altitude: location.coords.altitude,
Radius: location.coords.accuracy,
DateTime: new Date(location.timestamp).toISOString(),
Speed: location.coords.speed,
} as GPSData
}