将圆环拖到其他位置后,我试图获取圆心。从react-google-map文档中提供的示例代码中,他们在搜索框中使用它们来获取位置:
lifecycle({
componentWillMount() {
const refs = {}
this.setState({
bounds: null,
center: {
lat: 41.9, lng: -87.624
},
markers: [],
onMapMounted: ref => {
refs.map = ref;
},
onBoundsChanged: () => {
this.setState({
bounds: refs.map.getBounds(),
center: refs.map.getCenter(),
})
},
onSearchBoxMounted: ref => {
refs.searchBox = ref;
},
onPlacesChanged: () => {
const places = refs.searchBox.getPlaces();
const bounds = new google.maps.LatLngBounds();
我也用它来获得圆心:
lifecycle({
componentWillMount () {
const refs = {}
this.setState({
onCircleMounted: ref => {
refs.circle = ref
},
onCenterChanged: () => {
console.log(refs.circle.getCenter())
}
})
}
}),
withScriptjs,
withGoogleMap
)((props) =>
<GoogleMap
defaultZoom={props.zoomValue}
defaultCenter={props.centerFocus}
>
<Circle
key={marker.id}
center={{ lat: marker.lat, lng: marker.lng }}
radius={500}
draggable={true}
editable={true}
ref={props.onCircleMounted}
onCenterChanged={props.onCenterChanged}
/>
)
</GoogleMap>
)
但是我听不懂。它为refs.circle.getCenter()
返回了null。
有人知道怎么了吗?