我在 Android 上使用 React-native-maps 与 Expo,这需要将谷歌地图 APIKey 注入到应用程序中如 Expo 文档中所述。然后我在 EAS 上构建应用程序,当我使用地图运行页面视图时,它错误提示:
未找到 API 密钥。
这就是我所做的:
EXPO_PUBLIC_GOOGLE_MAPS_ANDROID_APIKEY_PROD
添加到我的本地 .env
和 EAS Secretapp.config
至:android: {
config: {
googleMaps: {
apiKey: process.env.EXPO_PUBLIC_GOOGLE_MAPS_APIKEY_PROD,
},
},
},
import MapView, { Marker, PROVIDER_GOOGLE, Region } from 'react-native-maps';
<MapView
initialRegion={region}
mapPadding={mapPadding}
provider={Platform.OS === 'android' ? PROVIDER_GOOGLE : undefined}
region={region}
{...rest}
>
<Marker
coordinate={...coords}
/>
</MapView>
"expo": "^49.0.1",
"react": "18.2.0",
"react-native": "0.72.10",
"react-native-maps": "1.7.1",
有什么想法吗?我也尝试过不通过
env
注入密钥。是 EAS 未正确注入密钥还是我的 app.config 不正确?
在 android/app/src/main/AndroidManifest.xml 文件中添加 API_KEY 对我有用,您需要在此处添加密钥
</activity>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="---apikey----"/>
</application>
</manifest>