I tried:
<GoogleMap
defaultZoom={14}
center={{lat: props.mapCenter.lat, lng: props.mapCenter.lng}}
onCenterChanged={getCenter()}
/>
Update: 我正在使用Stateless Functional Component
:
const MarkerClustererExampleGoogleMap = withGoogleMap(props => (
<GoogleMap
defaultZoom={14}
center={{lat: props.mapCenter.lat, lng: props.mapCenter.lng}}
onCenterChanged={getCenter()}
>
)
但我收到错误:
getCenter 未定义。
怎么解决这个问题,谢谢。
您可以调用类似的函数getCenter()
, getZoom()
, getBounds()
通过 React 从地图 API 等ref
到地图组件
这是一个粗略的示例,请注意这是一个未经测试的代码片段,应被视为伪代码,但它希望能让您了解如何进行此设置:
let ref
...
<GoogleMap
ref={(mapRef) => ref = mapRef} // bind the ref
onCenterChanged={() => {
ref.getCenter() // get the center, zoom, whatever using the ref
}}
/>
文档中有更多关于如何执行此操作的详细示例,例如here https://tomchentw.github.io/react-google-maps/#searchbox.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)