简体   繁体   English

React-Native-Maps 未在 Android 模拟器或真实设备上显示

[英]React-Native-Maps not showing on Android Emulator or real device

I added react-native-maps in my project and it doesn't showup我在我的项目中添加了 react-native-maps 并没有显示

I am not able to figure out what I'm doing wrong我无法弄清楚我做错了什么

Things I have tried:我尝试过的事情:

  • Test the example app available on the official repo: https://github.com/react-native-maps/react-native-maps测试官方 repo 上可用的示例应用程序: https ://github.com/react-native-maps/react-native-maps
  • Followed all the instructions available in the installation guide and also tried many articles guiding through the installation process遵循安装指南中提供的所有说明,并尝试了许多指导安装过程的文章

Please review the code snippets below and let me know if you need code from any other files that are important to find the issue.请查看下面的代码片段,如果您需要任何其他文件中对查找问题很重要的代码,请告诉我。

For some people it shows an empty map with white screen and Google logo at the bottom.对于某些人来说,它会显示一张空白地图,底部带有白色屏幕和 Google 徽标。 I have nothing at all.我什么都没有。 Just blank screen.只是黑屏。

Doesn't throw any error while compilation.编译时不会抛出任何错误。

code in Maps.js Maps.js 中的代码

import React from "react";
import { StyleSheet, View } from "react-native";
import MapView, { PROVIDER_GOOGLE } from "react-native-maps";

const Maps = () => {
  return (
    <View style={styles.container}>
      <MapView
        styles={styles.map}
        provider={PROVIDER_GOOGLE}
        initialRegion={{
          latitude: 37.78825,
          longitude: -122.4324,
          latitudeDelta: 0.0922,
          longitudeDelta: 0.0421,
        }}
      />
    </View>
  );
};

export default Maps;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    ...StyleSheet.absoluteFillObject,
    justifyContent: 'flex-end',
    alignItems: 'center',
  },
  map: {
    ...StyleSheet.absoluteFillObject,
    
  },
 });

\android\app\build.gradle file \android\app\build.gradle 文件

dependencies {
   ...
   implementation(project(':react-native-maps')){
       exclude group: 'com.google.android.gms', module: 'play-services-base'
       exclude group: 'com.google.android.gms', module: 'play-services-maps'
   }
   implementation 'com.google.android.gms:play-services-base:17.2.1'
   implementation 'com.google.android.gms:play-services-maps:17.0.0'
}

\android\build.gradle \android\build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        ndkVersion = "20.1.5948944"
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath('com.android.tools.build:gradle:4.2.1')
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

AndroidManifest.xml (Note: I have my API key and tested with the example project from the github repo and it worked) AndroidManifest.xml (注意:我有我的 API 密钥并使用来自 github 存储库的示例项目进行了测试,并且它有效)

<meta-data
     android:name="com.google.android.geo.API_KEY"
     android:value="I_ADDED_MY_KEY"/>

settings.gradle设置.gradle

include ':react-native-maps'
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/lib/android')

package.json包.json

{
  "name": "my-app",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@material-ui/core": "^4.12.3",
    "@material-ui/icons": "^4.11.2",
    "@react-native-async-storage/async-storage": "^1.15.9",
    "@react-native-community/checkbox": "^0.5.8",
    "@react-native-community/masked-view": "^0.1.11",
    "@react-navigation/bottom-tabs": "^6.0.7",
    "@react-navigation/drawer": "^5.12.9",
    "@react-navigation/native": "^5.9.8",
    "@react-navigation/stack": "^5.14.9",
    "axios": "^0.21.4",
    "react": "17.0.1",
    "react-dom": "^16.8.0",
    "react-native": "0.64.2",
    "react-native-bootsplash": "^3.2.4",
    "react-native-confirmation-code-input": "^1.0.4",
    "react-native-device-info": "^8.1.3",
    "react-native-extra-dimensions-android": "^1.2.5",
    "react-native-fast-image": "^8.3.7",
    "react-native-gesture-handler": "^1.10.3",
    "react-native-maps": "^0.29.3",
    "react-native-orientation-locker": "^1.3.1",
    "react-native-reanimated": "^2.2.0",
    "react-native-safe-area-context": "^3.3.2",
    "react-native-screens": "^3.7.0",
    "react-native-svg": "^12.1.1",
    "react-native-svg-transformer": "^0.14.3",
    "react-native-video": "^5.1.1"
  },
  "devDependencies": {
    "@babel/core": "^7.14.6",
    "@babel/runtime": "^7.14.6",
    "@react-native-community/eslint-config": "^3.0.0",
    "babel-jest": "^27.0.6",
    "eslint": "^7.30.0",
    "jest": "^27.0.6",
    "metro-react-native-babel-preset": "^0.66.0",
    "react-test-renderer": "17.0.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

您必须为 MapView 创建一个宽度、高度的样式: 复制它: map: { width: Dimensions.get('window').width, height: Dimensions.get('window').height, },它正在工作模拟器,但在真实设备中,我不确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Native 适用于真实设备,但不适用于 android 模拟器 - React Native works with a real device but not with an android emulator React-Native-Maps:未显示完整 map - React-Native-Maps: Not showing complete map 无法在具有React-Native-Maps依赖关系的Android设备或模拟器上运行React Native Project - Cannot run React Native Project on Android Device or Simulator with React-Native-Maps dependency FollowsUserLocation 不适用于 Android (react-native-maps) - FollowsUserLocation not working on Android (react-native-maps) 使用react-native-maps尝试在android模拟器中运行时出错 - Got an error while using react-native-maps try to run in android emulator Android Google Maps可在模拟器上使用,但不能在真实设备上使用 - Android Google Maps works on emulator but not on real device React-native:图片未在Android设备中显示; 但在模拟器中显示 - React-native: Images not showing in android device; but shows in emulator React-native:图像未在 android 设备中显示; 但在模拟器中完美显示 - React-native: Images not showing in android device; but shows perfectly in emulator 无法使react-native-maps在Android上工作 - Cannot make react-native-maps to work on android 一些自定义标记不会出现在 Android react-native-maps 上 - Some custom markers do not appear on Android react-native-maps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM