【发布时间】:2019-11-02 19:24:32
【问题描述】:
大家好,我正在尝试在 react.js 中实现谷歌地图,地图显示正常,但是当我尝试显示我的标记时,没有显示任何内容。如果我删除 lat 和 long 值,则标记将显示在地图顶部。但如果我向它添加 lat 和 long 值,它就会停止显示。有人可以帮忙吗?
import React, { Component } from 'react';
import GoogleMapReact from 'google-map-react';
import marker from './marker.png';
import { geolocated } from 'react-geolocated';
const AnyReactComponent = ({ text }) => (
<div>
<img src={marker} style={{ height: '50px', width: '50px' }} />
</div>
);
export default class Map extends Component {
static defaultProps = {
zoom: 11,
};
Componentwillmount() {
console.log(this.props.center.latitude);
}
render() {
return (
<div className="google-map" style={{ width: '100%', height: '2000px', backgroundColor: 'red' }}>
<GoogleMapReact
options={{
styles:ExampleMapStyles
}}
center={this.props.center} defaultZoom={this.props.zoom}>
<AnyReactComponent
lat={59.955413}
lng={30.337844}
text={'Kreyser Avrora'}
/>
</GoogleMapReact>
</div>
);
}
}
【问题讨论】:
标签: reactjs