必须将 AirGoogleMaps 目录添加到您的 xCode 项目以在 iOS React Native 上支持 GoogleMaps

AirGoogleMaps dir must be added to your xCode project to support GoogleMaps on iOS React Native

我正面临这个问题,我相信很多其他人经过一番搜索后也面临着这个问题。我正在尝试手动安装 Google 地图 IOS SDK 而不是 pods 方法。与 pods 有关的任何解决方案对我都不起作用。我能够渲染地图,但是当我提供 "provider google" 时,它会抛出错误。我需要 google 地图而不是苹果地图。 到目前为止我做了什么:

我的 package.json 片段:

"scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"   
 },   
 "dependencies": {
    "moment": "^2.22.2",
    "npm": "^6.5.0",
    "react": "16.6.3",
    "react-native": "0.57.8",
    "react-native-blur": "^3.2.2",
    "react-native-drawer": "^2.5.0",
    "react-native-elements": "^0.19.1",
    "react-native-maps": "^0.23.0",

我正在关注这个文档,除了一些小的调整之外,我认为它非常准确。

我的渲染地图的 React 本机组件。

import React from 'react'
import { ScrollView, View } from 'react-native'
import styles from './style'
import MapView, { PROVIDER_GOOGLE } from 'react-native-maps'

class Location extends React.Component {

  render () {
    return (
      <View style={styles.container}>
        <MapView
          provider={PROVIDER_GOOGLE} // remove if not using Google Maps
          style={styles.map}
          region={{
            latitude: 37.78825,
            longitude: -122.4324,
            latitudeDelta: 0.015,
            longitudeDelta: 0.0121,
          }}
        >
        </MapView>
      </View>
    )
  }
}

我的 Xcode 文件层次结构:

链接的库:

此外,我在构建设置中包含了 header 搜索中的路径。此外,我在 Xcode 中的库下包含了 AirMaps.xcodeproj。我已经看到更多 Podfile 的解决方案,但我很好奇是否有人通过解决此错误手动完成了它。我不确定我做错了什么。

终于在这里找到了我丢失的东西:Google Maps SDK for iOS requires GoogleMaps.bundle to be part of your target under 'Copy Bundle Resources

所以我所做的是安装 react-native 的步骤:

  1. npm install --save react-native-maps
  2. react-native link react-native-maps
  3. 从这里下载 google 地图 ios SDK [https://developers.google.com/maps/documentation/ios-sdk/start
  4. 按照步骤手动安装iosSDK,在第4步 google 文档步骤

    将以下包拖到您的项目中的 Frameworks 下 Xcode(出现提示时,select 根据需要复制项目):

    • GoogleMaps-2.7.0/Base/Frameworks/GoogleMapsBase.framework

    • GoogleMaps-2.7.0/Maps/Frameworks/GoogleMaps.framework

    • GoogleMaps-2.7.0/Maps/Frameworks/GoogleMapsCore.framework

  5. Right-click GoogleMaps.framework 在你的项目中,并且 select 显示在 发现者。它没有说的是...然后进入 child 文件夹 称为资源

  6. 将 GoogleMaps.bundle 从 Resources 文件夹拖到您的 项目。我们建议把它放在 Frameworks 文件夹下 Xcode。 出现提示时,确保将项目复制到目标组的 文件夹未 selected.
  7. 转到 Xcode 中的构建设置为您的项目输入“Header Search Paths”在搜索栏中双击debug可以看到 header 调试版本中的搜索路径。单击 + 添加路径和 使用递归选项添加“$(SRCROOT)/Frameworks/”。
  8. 转到 Xcode 中项目的构建阶段。添加以下内容 框架和库。

    • GoogleMapsBase.framework
    • GoogleMaps.framework
    • GoogleMapsCore.framework
    • libAirMaps.a 注意: 如果 libAirMaps.a 没有自动获得 linked 那么您可以通过将 AirMaps.xcodeproj 从 node_modules/react-native-maps/lib/ios 到 Libraries 文件夹 k/start

希望对大家有帮助 :)