React Native Expo Google 地图显示空白屏幕

问题描述 投票:0回答:1

我正在使用 Expo 开发一个 React Native 应用程序,并且我正在尝试将 Google 地图集成到主屏幕上。但是,地图无法加载,仅显示空白屏幕。相关代码和配置如下:

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

export default function HomeScreen() {
  return (
    <MapView
      provider={PROVIDER_GOOGLE}
      style={StyleSheet.absoluteFill}
      initialRegion={{
        latitude: 41.0082,
        longitude: 28.9784,
        latitudeDelta: 0.0922,
        longitudeDelta: 0.0421,
      }}
    >
      <Marker coordinate={{ latitude: 41.0082, longitude: 28.9784 }} />
    </MapView>
  );
}

app.json 配置:

"ios": {
  "googleServicesFile": "./GoogleService-Info.plist",
  "supportsTablet": true,
  "bundleIdentifier": "com.xxx.xxx.xxx",
  "config": {
    "googleMapsApiKey": "XXX"
  }
},

我已采取的步骤:

我在 app.json 的 ios.config 部分下添加了 googleMapsApiKey。 我确保在 MapView 中使用 PROVIDER_GOOGLE。 该应用程序具有位置访问权限。 我已在 Google Cloud Console 中验证了为 iOS 版 Google Maps SDK 启用了 API 密钥。 尽管执行了这些步骤,地图屏幕仍然空白。

我尝试过的:

确认googleMapsApiKey有效且无限制。 检查是否已在 Google Cloud Console 中启用适用于 iOS 的 Google Maps SDK。 使用 expo start -c 清理了 Expo 缓存。 重新构建应用程序并在物理设备和 iOS 模拟器上进行测试。 问题:

我是否缺少 iOS 上带有 Expo 的 Google 地图的任何配置? 由于我使用的是 Expo,我是否需要包含任何其他本机依赖项或步骤? Expo 处理 googleMapsApiKey 或权限的方式是否存在问题?

Api Key Restriction

Blank Map View

react-native expo react-native-maps
1个回答
0
投票

当我将博览会从 50 更新到 52 时,我遇到了同样的问题,而当我将提供商从“PROVIDER_GOOGLE”更改为“PROVIDER_DEFAULT”时,该错误得到了解决。 因此,只需导入“PROVIDER_DEFAULT”并使用“PROVIDER_DEFAULT”而不是“PROVIDER_GOOGLE”即可。

<MapView provider={PROVIDER_DEFAULT}></MapView>

版本

  1. “博览会”:“^52.0.18”,
  2. “反应本机”:“0.76.5”,
  3. “react-native-maps”:“1.18.0”,

enter image description here

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.