【发布时间】:2017-10-23 00:32:43
【问题描述】:
我在 React 中遇到了 Google Map 的问题。 一切都很好,但是当我尝试在这张地图中重新渲染其他地方时它不起作用:( 我的意思是当我改变城市(例如选择)时,使用了新的道具(纬度,经度),但是城市之一地图没有改变
import React from 'react';
import ReactDOM from 'react-dom';
import { withGoogleMap, GoogleMap, Marker } from "react-google-maps";
const SimpleMapExampleGoogleMap = withGoogleMap( props => {
console.log("here new props are used", props)
return <GoogleMap
defaultZoom={15}
defaultCenter={new google.maps.LatLng(props.lat, props.lng)}
/>
}
);
class GMap extends React.Component{
constructor(props) {
super(props);
this.state = {
lat: this.props.lat,
lng: this.props.lng
}
}
render() {
console.log("New props ", this.props)
return <SimpleMapExampleGoogleMap
lat={this.props.lat}
lng={this.props.lng}
containerElement={
<div style={{ height: `500px` }} />
}
mapElement={
<div style={{ height: `500px` }} />
}
/>
}
}
export { GMap }
【问题讨论】:
标签: javascript reactjs google-maps-api-3