Expo
iOSAndroid
Overview
DocyFieldLocationSelect uses community native modules for device-specific location features:
@react-native-community/geolocation— Access device GPS to get current coordinatesreact-native-geocoding— Reverse geocode coordinates to human-readable addresses (requires Google Maps API key)
Without these modules installed, the location picker still works with manual text search and predefined locations — but the "Use Current Location" button will be unavailable.
Installation
# Geolocation (for "Use Current Location" feature)
npx expo install @react-native-community/geolocation
# Reverse geocoding (for converting coordinates to addresses)
npm install react-native-geocodingGoogle Maps API Key
Reverse geocoding requires a Google Maps Geocoding API key. Pass it as a prop or set the EXPO_PUBLIC_GOOGLE_MAPS_API_KEY environment variable:
<DocyFieldLocationSelect
googleMapsApiKey="YOUR_API_KEY"
// ... other props
/>Compatibility
| Module | Expo Go | Dev Client | Bare RN |
|---|---|---|---|
@react-native-community/geolocation | No | Yes | Yes (auto-linked) |
react-native-geocoding | Yes (JS only) | Yes | Yes |
Note:
@react-native-community/geolocationrequires a development build — it does not work in Expo Go. The component handles this gracefully at runtime.
Usage
import { DocyFieldLocationSelect } from '@/components/docyrus-native/form-fields/docy-field-location-select';
<DocyFieldLocationSelect
label="Office Location"
allowCurrentLocation
showCoordinates
requestLocationPermission={async () => {
// Your permission handling logic
return 'granted';
}}
onChange={(location) => console.log(location)}
/>API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
value | LocationInfo | — | Current location value |
onChange | (value: LocationInfo) => void | — | Called when location changes |
placeholder | string | 'Select location' | Placeholder text |
allowCurrentLocation | boolean | true | Show "Use Current Location" button |
showCoordinates | boolean | true | Show coordinates under location items |
predefinedLocations | LocationInfo[] | Popular cities | Custom location list |
requestLocationPermission | () => Promise<'granted' | 'denied'> | — | Permission request callback |
googleMapsApiKey | string | EXPO_PUBLIC_GOOGLE_MAPS_API_KEY | Google Maps API key for geocoding |
LocationInfo Type
| Field | Type | Description |
|---|---|---|
name | string | Display name |
address | string? | Full address |
coordinates | { latitude: number; longitude: number }? | GPS coordinates |
country | string? | Country name |
city | string? | City name |
region | string? | Region/state |
postalCode | string? | Postal code |
type | 'current' | 'saved' | 'search'? | Location source |