Haz*_*Ali 13 javascript google-maps-markers react-native react-native-android react-native-ios
Hye,我是新的反应原生,想问我如何在地图中渲染多个标记.
这是我的代码
课内: -
constructor(props) {
super(props);
this.state = {
coordinate: ([{
latitude: 3.148561,
longitude: 101.652778,
title: 'hello'
},
{
latitude: 3.149771,
longitude: 101.655449,
title: 'hello'
}
]),
};
Run Code Online (Sandbox Code Playgroud)
}
内部渲染: -
<MapView
style={styles.map}
showsUserLocation={true}
followUserLocation={true}
zoomEnabled={true}
//annotations={markers}
>
<MapView.Marker
coordinate={this.state.coordinate}
title={this.state.coordinate.title}
/>
</MapView>
Run Code Online (Sandbox Code Playgroud)
我想在地图中渲染这两个标记,我不知道如何在本地生成循环来渲染它.我已经尝试了文档中的内容,但仍然没有工作.
先感谢您 :)
vin*_*ayr 34
coordinate财产安置不正确.做这样的事情 -
this.state = {
markers: [{
title: 'hello',
coordinates: {
latitude: 3.148561,
longitude: 101.652778
},
},
{
title: 'hello',
coordinates: {
latitude: 3.149771,
longitude: 101.655449
},
}]
}
Run Code Online (Sandbox Code Playgroud)
里面渲染
<MapView
....
>
{this.state.markers.map(marker => (
<MapView.Marker
coordinate={marker.coordinates}
title={marker.title}
/>
))}
</MapView>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15888 次 |
| 最近记录: |