You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have followed the code as per the document but when the map is loaded for the first time then the page breaks and when I load it for the second time then everything works fine
"use client";
import React, { useState, useCallback, useEffect, useRef } from "react";
import {
GoogleMap,
useLoadScript,
Marker,
Autocomplete,
} from "@react-google-maps/api";
const LIBRARIES = ["places"];
const isMobile =
typeof window !== "undefined" &&
window.innerWidth > 250 &&
window.innerWidth < 600;
const mapContainerStyle = {
width: isMobile ? "100%" : "50%", // 640px corresponds to 'sm' size in Tailwind
height: "400px",
};
const defaultCenter = {
lat: 40.712776,
lng: -74.005974,
};
const GoogleMapComponent = ({
paddress,
setPaddress,
latlong,
setLatlong,
serachError,
onLocationSearch,
}) => {
const { isLoaded, loadError } = useLoadScript({
googleMapsApiKey: process.env.NEXT_PUBLIC_MAPS_KEY,
libraries: LIBRARIES,
});
const [marker, setMarker] = useState(null);
const [localAddress, setLocalAddress] = useState(paddress || "");
useEffect(() => {
if (latlong.latitude && latlong.longitude) {
setMarker({
lat: Number(latlong.latitude),
lng: Number(latlong.longitude),
});
}
}, [latlong]);
const [autocomplete, setAutocomplete] = useState(null);
const mapRef = useRef();
The text was updated successfully, but these errors were encountered: