[英]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:我尝试过的事情:
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.