2017-03-03 115 views
0

我有一个iOS的反应本机应用程序在它的地图,我试图得到一些关于它的标记,但我不断收到以下错误ReactNative添加标记到地图中的异常标记,预计

意外令牌,预计...

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

这是我的构造函数:

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

你的错误是你把标记“MapView.Marker”里面在 “MapView的”

代码那张正与此

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} 
 
        /> 
 
       ))} 
 
       </MapView> 
 

 
     );

+0

这真的帮我动态放置MapMarker动态。 BTW,marker.coordinates和marker.title仅仅是逻辑名称。我们可以使用其他的东西,比如marker.geoposition和marker.businessname。但是在我看到的所有代码示例中,我只能看到marker.coodinates等等。仅供参考。 –