Hooks
useCurrentPosition
const position: Position | undefined = useCurrentPosition()Use the device's location to update a marker or a coordinate readout.
Return Values
position is the latest reading, or undefined if none is available. An absent reading alone doesn't mean permission was denied.
Prop
Type
Example
import { useCurrentPosition } from '@mapquest/sdk'
import { Text } from 'react-native'
export function LocationReadout() {
const position = useCurrentPosition()
if (!position) return <Text>Location unavailable</Text>
const [longitude, latitude] = position.location.coordinates
return <Text>{latitude.toFixed(5)}, {longitude.toFixed(5)}</Text>
}Your app owns the permission prompt. If permission is granted after the screen mounts, the hook can receive a reading without a remount. A new reading can reflect a change in accuracy or speed, not just movement; don't treat each update as distance traveled.