Back to React Native Vision Camera

Location

docs/content/docs/location.mdx

5.2.32.7 KB
Original Source

import { Tab, Tabs } from 'fumadocs-ui/components/tabs'

Captured Photos (see "A Photo") and Videos (see "The Recorder") can contain Location tags in their EXIF flags or video metadata.

[!DEPENDENCY] Location requires react-native-vision-camera-location to be installed.

Get a Location

To get a Location, use a LocationManager from react-native-vision-camera-location:

<Tabs items={["Hooks", "Imperative"]} groupId="hooks-or-imperative" persist> <Tab value="Hooks">

tsx
const location = useLocation({ /* options */ })

useEffect(() => {
  if (!location.hasPermission) {
    location.requestPermission()
  }
}, [location.hasPermission])

if (location.hasPermission) {
  console.log(location.location)
}
</Tab> <Tab value="Imperative"> ```ts const locationManager = createLocationManager({ /* options */ })

if (locationManager.locationPermissionStatus !== 'authorized') { const hasPermission = await locationManager.requestLocationPermission() if (!hasPermission) return }

await locationManager.startUpdating() locationManager.addOnLocationChangedListener((location) => { console.log(location) })

</Tab>
</Tabs>

#### Manually creating a Location

Alternatively, you can create a custom [`Location`](/api/react-native-vision-camera/hybrid-objects/Location) using [`createLocation(...)`](/api/react-native-vision-camera-location/functions/createLocation), which can be useful for testing or spoofing location:

```ts
const location = createLocation(48.2084, 16.3735)

Adding Location tags to Photos

To add a Location to a Photo, pass a custom location to capturePhoto(...):

ts
const photoOutput = ...
const location = ...
const photo = await photoOutput.capturePhoto(
  { location: location },
  { /* callbacks */ }
)

Adding Location tags to Videos

To add a Location to a captured Video, pass a custom location to createRecorder(...):

ts
const videoOutput = ...
const location = ...
const recorder = await videoOutput.createRecorder({
  location: location
})