JustFly1984 / react-google-maps-api

React Google Maps API
MIT License
1.76k stars 426 forks source link

Error: Loader must not be called again with different options. #3221

Closed Shad0w59i closed 1 year ago

Shad0w59i commented 1 year ago

Please provide an explanation of the issue

Hello, I get an error when I use "useJsApiLoader" under NextJS

Package.json : "dependencies": { "@radix-ui/react-popover": "^1.0.5", "@react-google-maps/api": "^2.18.1", "classnames": "^2.3.2", "eslint": "8.36.0", "eslint-config-next": "13.1.1", "focus-trap-react": "^10.1.1", "framer-motion": "^10.9.1", "lucide-react": "^0.128.0", "next": "13.2.4", "next-auth": "^4.20.1", "postcss": "^8.4.21", "prettier": "^2.8.7", "prettier-plugin-tailwindcss": "^0.2.5", "react": "18.2.0", "react-dom": "18.2.0", "react-wrap-balancer": "^0.4.0" }, "devDependencies": { "@tailwindcss/forms": "^0.5.3", "@tailwindcss/line-clamp": "^0.4.2", "@tailwindcss/typography": "^0.5.9", "autoprefixer": "^10.4.14", "tailwindcss": "^3.2.7" }

ERROR :

image

CODE :


import { motion } from 'framer-motion'

const containerStyle = {
  width: '100%',
  height: '500px',
}

const center = {
  lat: 37.7749,
  lng: -122.4194,
}

export default function GoogleMaps() {
  const { isLoaded } = useJsApiLoader({
    googleMapsApiKey: process.env.API_KEY_GOOGLE_MAPS,
  })

  if (!isLoaded) {
    return (
      <div role="status" className="space-y-8 animate-pulse md:space-y-0 md:space-x-8 md:flex md:items-center">
        <div className="flex items-center justify-center w-full h-48 bg-gray-300 rounded sm:w-96 dark:bg-gray-700">
          <svg className="w-12 h-12 text-gray-200" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" viewBox="0 0 640 512"><path d="M480 80C480 35.82 515.8 0 560 0C604.2 0 640 35.82 640 80C640 124.2 604.2 160 560 160C515.8 160 480 124.2 480 80zM0 456.1C0 445.6 2.964 435.3 8.551 426.4L225.3 81.01C231.9 70.42 243.5 64 256 64C268.5 64 280.1 70.42 286.8 81.01L412.7 281.7L460.9 202.7C464.1 196.1 472.2 192 480 192C487.8 192 495 196.1 499.1 202.7L631.1 419.1C636.9 428.6 640 439.7 640 450.9C640 484.6 612.6 512 578.9 512H55.91C25.03 512 .0006 486.1 .0006 456.1L0 456.1z"/></svg>
        </div>
        <span className="sr-only">Loading...</span>
      </div>
    )
  }

  return (
    <motion.div initial={{ opacity: 0 }} animate={{ opacity: 1 }}>
      <GoogleMap mapContainerStyle={containerStyle} center={center} zoom={12}>
        <Marker position={center} />
      </GoogleMap>
    </motion.div>
  )
}
ahmadkhalaf1 commented 1 year ago

@Shad0w59i Hello , i am getting this error and its driving me crazy , have you find a fix ? pleas help