Advertisement
Fhernd

Untitled

Sep 29th, 2023
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.64 KB | Software | 0 0
  1. import React, { useState } from 'react';
  2. import { GoogleMap, LoadScript } from '@react-google-maps/api';
  3.  
  4. function MapComponent() {
  5.   const [zoom, setZoom] = useState(8); // Initial zoom level
  6.  
  7.   const handleZoomChanged = (map) => {
  8.     setZoom(map.getZoom());
  9.   }
  10.  
  11.   return (
  12.     <LoadScript googleMapsApiKey="YOUR_GOOGLE_MAPS_API_KEY">
  13.       <GoogleMap
  14.         id="example-map"
  15.         mapContainerStyle={{ width: '400px', height: '400px' }}
  16.         center={{ lat: -34.397, lng: 150.644 }}
  17.         zoom={zoom}
  18.         onZoomChanged={(map) => handleZoomChanged(map)}
  19.       />
  20.     </LoadScript>
  21.   );
  22. }
  23.  
  24. export default MapComponent;
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement