我想在react-google-maps 中获取地图的当前缩放级别,就像我们使用 getZoom() 函数在简单的谷歌地图 API 中所做的那样。如何在react-google-maps中做到这一点?
我看过很少的答案,但没有一个对我有用。
import React from "react"
import {
GoogleMap,
Marker,
withGoogleMap,
withScriptjs,
} from "react-google-maps"
const Map = () => {
return (
<GoogleMap
defaultZoom={15}
defaultCenter={{ lat: lat, lng: lng }}
>
<Marker position={{ lat: lat, lng: lng }} />
</GoogleMap>
)
}
const WrappedMap = withScriptjs(withGoogleMap(Map))
const Index = () => {
return (
<Layout>
<WrappedMap
googleMapURL={`https://maps.googleapis.com/maps/api/js?
key=my_key&v=3.exp&libraries=geometry,drawing,places`}
loadingElement={<Loading />}
containerElement={<div style={{ height: `400px` }} />}
mapElement={<div style={{ height: `100%` }} />}
/>
</Layout> …Run Code Online (Sandbox Code Playgroud)