1import { AndroidConfig, ConfigPlugin, IOSConfig, withInfoPlist } from '@expo/config-plugins'; 2import resolveFrom from 'resolve-from'; 3 4import { createLegacyPlugin } from './createLegacyPlugin'; 5 6const LOCATION_USAGE = 'Allow $(PRODUCT_NAME) to access your location'; 7 8// Copied from expo-location package, this gets used when the 9// user has react-native-maps installed but not expo-location. 10const withDefaultLocationPermissions: ConfigPlugin = (config) => { 11 const isLinked = 12 !config._internal?.autolinkedModules || 13 config._internal.autolinkedModules.includes('react-native-maps'); 14 // Only add location permissions if react-native-maps is installed. 15 if ( 16 config._internal?.projectRoot && 17 resolveFrom.silent(config._internal.projectRoot, 'react-native-maps') && 18 isLinked 19 ) { 20 config = withInfoPlist(config, (config) => { 21 config.modResults.NSLocationWhenInUseUsageDescription = 22 config.modResults.NSLocationWhenInUseUsageDescription || LOCATION_USAGE; 23 return config; 24 }); 25 26 return AndroidConfig.Permissions.withPermissions(config, [ 27 'android.permission.ACCESS_COARSE_LOCATION', 28 'android.permission.ACCESS_FINE_LOCATION', 29 ]); 30 } 31 return config; 32}; 33 34export default createLegacyPlugin({ 35 packageName: 'react-native-maps', 36 fallback: [ 37 AndroidConfig.GoogleMapsApiKey.withGoogleMapsApiKey, 38 IOSConfig.Maps.withMaps, 39 withDefaultLocationPermissions, 40 ], 41}); 42