问题描述
我正在使用 React Native 在应用程序中构建地图视图.但是当我运行应用程序时出现此错误:
I'm building mapview in the app by using react native. but I got this error when I run the application:
检查'App'的渲染方法
这段代码有什么问题?抱歉,我是 React Native 的新手.
What's wrong with this code? Sorry I'm new in react native.
App.js
import React, {Component, Fragment} from 'react';
import {
Platform,
StyleSheet,
View,
MapView
} from 'react-native';
type Props = {};
export default class App extends Component<Props> {
render() {
return (
<View style={styles.container}>
<MapView
style={styles.map}
provider={null}
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
justifyContent: 'flex-end',
alignItems: 'center',
},
map: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
},
});
index.js
import { AppRegistry } from 'react-native';
import App from './App';
AppRegistry.registerComponent('newapp', () => App);
推荐答案
取决于您创建应用程序的方式,但您的 MapView
导入不正常.MapView
不是 react-native sdk 组件.
Depending how you created your app but your MapView
import is not ok.MapView
is not a react-native sdk component.
你可以去MapView官方git hub安装,然后
从'react-native-maps'导入MapView
;
或者,您可以使用 Expo MapView(如果您创建了您的应用程序)并添加以下行:
Or, you can use Expo MapView (if you created your app from the tool) and add this line:
import { MapView } from 'expo';
无需安装任何其他东西.两个版本是一样的东西.
without installing anything else. The two versions are the same things.
这篇关于Mapview - 检查“App"的渲染方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!