【问题标题】:react-native-maps marker throwing and IndexOutofBoundsException: Invalid index 1, size is 0react-native-maps 标记抛出和 IndexOutofBoundsException: Invalid index 1, size is 0
【发布时间】:2017-01-27 12:03:01
【问题描述】:

我正在尝试让 react-native-maps Marker 显示在我的 Android 设备上(它在 iOS 上工作得非常好)但它给我一个 IndexOutofBoundsException: Invalid index 1, size is 0 error at render time。

http://i.imgur.com/owletnw.png

render() {
    const INITIAL_REGION = { latitude: 52.221835, longitude: 21.000896, latitudeDelta: 0.0922, longitudeDelta: 0.0421 };
    return (
        <MapView ref="map"
            showsUserLocation = { true }
            loadingEnabled = { true }
            showsTraffic = { false }
            showsBuildings = { false }
            style = { styles.map, {flex: 1} }
            initialRegion = { INITIAL_REGION }
        >
            <View style={{flex: 0.1, flexDirection: 'row', position: 'absolute', justifyContent: 'space-between', backgroundColor: 'transparent'}}>
                <Button onPress={() => this.showWithinRadius(5)}>Wszystkie ~5km</Button>
                <Button onPress={() => this.showWithinRadius(10)}>Wszystkie ~10km</Button>
                <Button onPress={() => this.showWithinRadius(15)}>Wszystkie ~15km</Button>
                <Button onPress={() => this.showAllOffers()}>Wszystkie oferty</Button>
            </View>
            { console.log(this.state.offerLocation) }
            <Marker
                coordinate = { {latitude: 52.259216308593, longitude: 21.041564941406} }
                title = { this.props.selectedOffer.offer.title }
            />
        </MapView>
    );
}

知道是什么导致了这种行为吗?我尝试从 MapView 组件中删除 View 块,但这似乎没有帮助。在实际的应用程序中,我计划通过一个似乎在 fitToCoordinates 方法中工作的对象传递坐标。

【问题讨论】:

    标签: react-native react-native-android react-native-maps


    【解决方案1】:

    没有针对此问题提供任何解决方案,但它帮助我理解并解决了我的问题。 我不认为View 是问题,而是组件的呈现顺序。 看起来,在 Android 上,渲染顺序很重要。 因此,将 Markers 渲染为 MapView 的第一个子级为我修复了它。

    这里也提到了: https://github.com/react-community/react-native-maps/issues/291

    希望我能帮上忙!

    【讨论】:

      【解决方案2】:

      没关系,实际上是 MapView 中的 View 组件导致了问题。

      【讨论】:

      • 但我想在设计城和搜索栏选项中显示 On Mapview 如何插入
      • 如果您能解释一下 View 组件的问题,那就太好了!
      【解决方案3】:

      把内视图和市场放在一个视图中,这样就解决了问题。

      【讨论】:

        【解决方案4】:

        对我来说,解决方案是从中删除任何视图(可以是视图、图像等)。 它与对象无关,也与订单无关。

        【讨论】:

          猜你喜欢
          • 2016-08-12
          • 2016-03-30
          • 1970-01-01
          • 2018-08-01
          • 2020-02-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多