latlng不能为null,需要职位 ReactNative

问题描述

我正在尝试向地图添加标记。我想将所有位置数据保存在一个单独的文件中,因此我试图从data.json文件提取坐标。 latlng坐标位于json文件的数组中。我使用的位置属性不正确吗?

 render() {
    return (
      <View style={styles.container}>
        <DestinationButton />
        <CurrentLocationButton
          cb={() => {
            this.centerMap();
          }}
        />
        <MapView
          initialRegion={this.state.region}
          showsUserLocation={true}
          showsCompass={true}
          rotateEnabled={false}
          ref={(map) => {
            this.map = map;
          }}
          style={{ flex: 1,zIndex: 0 }}
        >
          {data.features.map((tc) => (
            <Marker
              key={tc.properties.NAME}
              position={{
                lat: tc.geometry.coordinates[1],lng: tc.geometry.coordinates[0],}}
            />
          ))}
        </MapView>
      </View>
    );
  }

解决方法

似乎您为<Marker/>提供了错误的道具,应该是坐标而不是位置。根据文档:https://github.com/react-native-maps/react-native-maps#rendering-a-list-of-markers-on-a-map

<Marker 
  key={tc.properties.NAME} 
  coordinate={{
    latitude: tc.geometry.coordinates[1],longitude: tc.geometry.coordinates[0],}}
/>

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...