【发布时间】:2017-10-11 18:47:12
【问题描述】:
我不想在地图上显示从某些移动设备中挑选的位置。 有关位置的数据在那里..
我这里需要的是根据从服务器接收到的数据在地图上添加标记。
假设我已将位置数据 ({Lat,Lang}) 设置为 状态标记 那么如何添加它以显示在地图中。
我的地图代码如下!
import React, { Component } from 'react';
import GoogleMapReact from 'google-map-react';
const AnyReactComponent = ({ text }) => <div>{text}</div>;
class MyClass extends Component {
constructor(props){
super(props);
}
render() {
return (
<GoogleMapReact
defaultCenter={this.props.center}
defaultZoom={this.props.zoom}
style={{height: '300px'}}
>
<AnyReactComponent
lat={59.955413}
lng={30.337844}
text={'Google Map'}
/>
</GoogleMapReact>
);
}
}
MyClass.defaultProps = {
center: {lat: 59.95, lng: 30.33},
zoom: 11
};
export default MyClass;
此代码来自答案Implementing google maps with react
使用的 npm 包:- google-map-react
【问题讨论】:
标签: javascript reactjs google-maps