小编use*_*818的帖子

如何在react-google-maps中获取地图[getZoom()]的当前缩放?

我想在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)

google-maps reactjs react-google-maps

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

google-maps ×1

react-google-maps ×1

reactjs ×1