ReactNative向地图添加标记预期的意外标记

时间:2017-03-03 13:45:26

标签: google-maps react-native maps react-native-ios

我有一个iOS反应原生应用程序,里面有一张地图,我正在尝试获取一些标记,但我一直收到以下错误

  

预期的令牌,预期......

任何人都知道这里发生了什么?

这是我的构造函数:

constructor(props) {
        super(props);
        this.state = {
            isFirstLoad: true,
            annotations: [],
            mapRegion: undefined,
            markers: [{
                title: 'Marker1',
                coordinates: {
                    latitude: 3.148561,
                    longitude: 101.652778
                },
            },
            {
                title: 'Marker2',
                coordinates: {
                    latitude: 3.149771,
                    longitude: 101.655449
                },
            }]
        };
    }

我的渲染功能:

return (
            <MapView
                style={ styles.map }
                onRegionChangeComplete={onRegionChangeComplete}
                region={this.state.mapRegion}
                annotations={this.state.annotations}
                zoomEnabled={true}
                showsUserLocation={true}

                {this.state.markers.map(marker => (
                    <MapView.Marker
                        coordinate={marker.coordinates}
                        title={marker.title}
                    />
                ))}
            />
        );

抱怨这一行:{this.state.markers.map(marker => (

非常感谢任何帮助:)

1 个答案:

答案 0 :(得分:2)

您的错误是您将“MapView.Marker”标记放在“MapView”中

您的代码正在使用此

let disposeBag = DisposeBag()

let dataSources = RxCollectionViewSectionedReloadDataSource<Travelers>()

let viewModel = TravelerViewModel()

lazy var travelerCollectionView: UICollectionView = {
    let layout = UICollectionViewFlowLayout()
    layout.minimumInteritemSpacing = 0
    layout.minimumLineSpacing = 0
    layout.scrollDirection = .horizontal
    layout.itemSize = CGSize(width: 44, height: 44)

    let travelerCollectionView = UICollectionView(frame: CGRect(x: 100, y: 100, width: 100, height: 100), collectionViewLayout: layout)
    travelerCollectionView.backgroundColor = .red
    travelerCollectionView.register(TravelerItemCell.self, forCellWithReuseIdentifier: TravelerItemCell.identifier)
    return travelerCollectionView
}()

override init(frame: CGRect) {
    super.init(frame: frame)
    addSubview(travelerCollectionView)

    viewModel.items.asObservable()
        .bind(to: travelerCollectionView.rx.items(dataSource: dataSources))
        .addDisposableTo(disposeBag)

    dataSources.configureCell = { (_, collection, indexPath, traveler) in
        let cell = collection.dequeueReusableCell(withReuseIdentifier: TravelerItemCell.identifier, for: indexPath) as! TravelerItemCell
        cell.setAvaterImage(avater: traveler.avater)
        return cell
    }
}