Bis*_*ret 5 marker react-native-maps
请删除此问题,有人在另一个主题上帮助了我.
我试图在我的应用程序中的某些时间生成标记,以便在启动时显示空白地图,但稍后,标记可以在某些时间显示并消失.
我的状态变量设置如下:
class Map extends Component {
state = {
markers: [{
key: null,
contactName: null,
location: null,
}]
}
Run Code Online (Sandbox Code Playgroud)
我试图生成标记的代码如下:
renderMarker = ({ key, contactName, location }) => {
console.log('renderMarker: ' + key + ', ' + contactName + ', ' + location);
return this.state.markers.map(Marker => (
<MapView.Marker
key = { key }
coordinate = {{
latitude: location[0],
longitude: location[1]
}}
//image = { carIcon }
title = { contactName } />
))
}
Run Code Online (Sandbox Code Playgroud)
那里的console.log正在生成正确的数据,所以它返回例如:
renderMarker: 389djhJHDjdkh392sdk, Steve, -30.498767387,120.4398732
Run Code Online (Sandbox Code Playgroud)
我的渲染函数如下所示:
render() {
return (
<MapContainer>
<MapView
style = { styles.map }
region = { this.state.mapRegion }
showsUserLocation = { true }
followUserLocation = { true }
onRegionChangeComplete = { this.onRegionChangeComplete.bind(this) }>
</MapView>
</MapContainer>
)
}
Run Code Online (Sandbox Code Playgroud)
但地图上没有任何内容.我一直在搜索互联网,但我找不到一个可以跟随的例子.我是否需要在render()函数中添加一些内容才能使其工作?我的想法是我不需要的,因为renderMarker正在做这项工作.
有什么想法吗?