Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

GoogleMap: center or defaultCenter property must be defined

function App() {
  const mapRef = useRef(null);
  const [position, setPosition] = useState({
      lat: 41, 
      lng: -71
  });

  function handleLoad(map) {
    mapRef.current = map;
  }

  function handleCenter() {
    if (!mapRef.current) return;

    const newPos = mapRef.current.getCenter().toJSON();
    setPosition(newPos);
  }

  return (
    <GoogleMap
      zoom={4}
      onLoad={handleLoad}
      onDragEnd={handleCenter}
      center={position}
      id="map"
      mapContainerStyle={{
        height: '900px',
        width: '900px'
      }}
    >
   </GoogleMap>
  );
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: socket-client-io for reconnection in js or javascript 
Javascript :: Find All Less Than Equal To In MongoDB 
Javascript :: node js simple server 
Javascript :: nodejs stream 
Javascript :: chaining async await 
Javascript :: add new array at the back of react state 
Javascript :: event delegation javascript 
Javascript :: replit node version 
Javascript :: convert angular HTTP to Native HTTP in Ionic 
Javascript :: prisma where not in array 
Javascript :: set time slots with date in javascript 
Javascript :: discord.js reading json object from json 
Javascript :: backdrop issue with multiple modal 
Javascript :: how to use react fragment 
Javascript :: submit form jquery browser check 
Javascript :: create and get all the files in a directory with nodejs 
Javascript :: angular set attribute value dynamically 
Javascript :: Cypress failed to make a connection to the Chrome DevTools Protocol after retrying for 50 seconds. 
Javascript :: how to apply reduce to an empty array in javascript 
Javascript :: elixir guards 
Javascript :: Remove an item by index position 
Javascript :: js round floar 
Javascript :: JavaScript catch() method 
Javascript :: how to add object to array javascript 
Javascript :: addition of time in javascript 
Javascript :: 9 + 10 
Javascript :: jquery select 
Javascript :: bubbling and capturing in javascript 
Javascript :: ReactComponent as Icon 
Javascript :: javascript arrow functions to create methods inside objects 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =