diff --git a/README.md b/README.md index accb338..d0ff99f 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,23 @@ navigator.geolocation = require('@react-native-community/geolocation'); ```javascript import Geolocation from '@react-native-community/geolocation'; -Geolocation.getCurrentPosition(info => console.log(info)); +function() Example() { + useEffect(() => { + Geolocation.setRNConfiguration({ + skipPermissionRequests: false, + authorizationLevel: 'whenInUse', + locationProvider: 'auto', + }); + + Geolocation.getCurrentPosition( + pos => console.debug('Geolocation.getCurrentPosition Result', JSON.stringify(pos)), + error => console.error('Geolocation.getCurrentPosition Error', JSON.stringify(error)), + {enableHighAccuracy: true}, + ); + }; + + // ... +} ``` Check out the [example project](example) for more examples. @@ -128,7 +144,7 @@ Sets configuration options that will be used in all location requests. ```ts Geolocation.setRNConfiguration( config: { - skipPermissionRequests: boolean; + skipPermissionRequests?: boolean; authorizationLevel?: 'always' | 'whenInUse' | 'auto'; locationProvider?: 'playServices' | 'android' | 'auto'; } diff --git a/js/NativeRNCGeolocation.ts b/js/NativeRNCGeolocation.ts index 6a16178..bf08c44 100644 --- a/js/NativeRNCGeolocation.ts +++ b/js/NativeRNCGeolocation.ts @@ -2,7 +2,7 @@ import type { TurboModule } from 'react-native'; import { TurboModuleRegistry } from 'react-native'; export type GeolocationConfiguration = { - skipPermissionRequests: boolean; + skipPermissionRequests?: boolean; authorizationLevel?: 'always' | 'whenInUse' | 'auto'; locationProvider?: 'playServices' | 'android' | 'auto'; }; @@ -40,8 +40,9 @@ export type GeolocationError = { export interface Spec extends TurboModule { setConfiguration(config: { - skipPermissionRequests: boolean; + skipPermissionRequests?: boolean; authorizationLevel?: string; + locationProvider?: string; }): void; requestAuthorization( success: () => void, diff --git a/js/implementation.native.ts b/js/implementation.native.ts index 28e0f34..7d0647d 100644 --- a/js/implementation.native.ts +++ b/js/implementation.native.ts @@ -44,13 +44,13 @@ let updatesEnabled = false; */ export function setRNConfiguration(config: GeolocationConfiguration) { RNCGeolocation.setConfiguration({ - ...config, + skipPermissionRequests: config.skipPermissionRequests, authorizationLevel: - config?.authorizationLevel === 'auto' + config.authorizationLevel === 'auto' ? undefined : config.authorizationLevel, locationProvider: - config?.locationProvider === 'auto' ? undefined : config.locationProvider, + config.locationProvider === 'auto' ? undefined : config.locationProvider, }); }