【问题标题】:Mapview - Check the render method of 'App'Mapview - 检查“App”的渲染方法
【发布时间】:2018-06-05 04:01:43
【问题描述】:

我正在使用本机反应在应用程序中构建地图视图。但是当我运行应用程序时出现此错误:

检查'App'的渲染方法

这段代码有什么问题?抱歉,我是 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);

【问题讨论】:

    标签: react-native


    【解决方案1】:

    取决于您创建应用的方式,但您的 MapView 导入不正确。 MapView 不是 react-native sdk 组件。

    你可以去MapView official git hub,安装它,然后

    import MapView from 'react-native-maps';

    或者,您可以使用 Expo MapView(如果您使用该工具创建应用)并添加以下行:

    import { MapView } from 'expo';

    无需安装其他任何东西。这两个版本是一样的东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-17
      • 2021-08-03
      • 2018-02-13
      • 1970-01-01
      • 2021-07-12
      • 2019-01-17
      • 2019-08-22
      • 1970-01-01
      相关资源
      最近更新 更多