You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native/Expo添加PROVIDER_GOOGLE后出现bubblingEventTypes空值错误

解决MapView添加PROVIDER_GOOGLE后出现Cannot read property 'bubblingEventTypes' of null错误

以下是针对该问题的常见解决方案,按优先级尝试:

1. 确认PROVIDER_GOOGLE的正确导入

确保从react-native-maps中正确解构导入PROVIDER_GOOGLE,避免路径错误或未导入的情况:

import MapView, { PROVIDER_GOOGLE } from 'react-native-maps';

2. Expo环境下配置Google Maps API密钥

若使用Expo框架,必须在app.json或app.config.js中配置对应平台的Google Maps API密钥,否则Google Maps无法正常初始化,进而触发该错误:

{
  "expo": {
    "android": {
      "config": {
        "googleMaps": {
          "apiKey": "你的安卓Google Maps API密钥"
        }
      }
    },
    "ios": {
      "config": {
        "googleMapsApiKey": "你的iOS Google Maps API密钥"
      }
    }
  }
}

配置完成后,重启Expo服务并清除缓存。

3. 确保依赖版本兼容

使用Expo官方提供的兼容版本安装react-native-maps,避免直接安装原生版本导致的兼容性问题:

npx expo install react-native-maps

若是裸React Native项目,需检查react-native-maps版本与当前RN版本是否匹配,可参考官方文档的版本对应表调整。

4. 清理项目缓存

缓存异常可能导致组件初始化失败,执行以下操作清理缓存:

  • Expo项目:
    npx expo start --clear
    
  • 裸RN安卓项目:
    cd android && ./gradlew clean && cd ..
    
  • 裸RN iOS项目:
    cd ios && pod deintegrate && pod install && cd ..
    

5. 裸RN项目的原生配置检查

若是裸React Native项目,需确保原生端配置正确:

  • 安卓:在AndroidManifest.xml中添加Google Maps API密钥:
    <meta-data
      android:name="com.google.android.geo.API_KEY"
      android:value="你的安卓API密钥"/>
    
  • iOS:在Info.plist中添加API密钥:
    <key>GoogleMapsApiKey</key>
    <string>你的iOS API密钥</string>
    

内容的提问来源于stack exchange,提问作者null_voyager

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 05:06:04