【发布时间】:2017-11-17 02:04:45
【问题描述】:
在Meteor 1.5 中使用 React JS
问题:需要一种方法来添加 Marker 使用 react-google-maps
使用 ES6 和 JSX 格式
遵循文档并能够嵌入地图,但无法添加标记。
这是我的代码:
const InitialMap = withGoogleMap(props => {
var index = this.marker.index || [];
return(
<GoogleMap
ref={props.onMapLoad}
defaultZoom={14}
defaultCenter={{lat: 40.6944, lng:-73.9213}}
>
<Marker
key={index}
position={marker.position}
onClick={() => props.onMarkerClick(marker)}
/>
</GoogleMap>
)
});
export default class MapContainer extends Component{
constructor(props){
this.state = {
markers:[{
position:{
lat: 255.0112183,
lng:121.52067570000001,
}
}]
}
}
render(){
return(
<div style={{height:"100%"}}>
<InitialMap
containerElement={
<div style={{height:"100%"}}/>
}
mapElement={
<div style={{height:"100%"}} />
}
markers={this.state.markers} />
</div>
)
}
}
【问题讨论】:
-
有相同问题的朋友请关注作者提供的demo。
标签: javascript google-maps reactjs google-maps-api-3 google-maps-markers