JustFly1984 / react-google-maps-api

React Google Maps API
MIT License
1.75k stars 421 forks source link

Load google maps asynchronously #3339

Closed nitya-nalamari closed 4 months ago

nitya-nalamari commented 4 months ago

Reason:

The make-load-script-url file does not add loading=async to its script. This results in a warning that google maps api should be loaded asynchronously for optimal performance.

Ref: https://developers.google.com/maps/documentation/javascript/overview

Issue: #3334

MohammedWaheeb commented 4 months ago

This is much needed

antoniocolelli commented 4 months ago

Just change the way you load the api.

Use this:

import {useJsApiLoader} from "@react-google-maps/api";

const {isLoaded, loadError} = useJsApiLoader({ id: 'google-map-script', googleMapsApiKey: YOUR_GOOGLE_MAPS_KEY, });

SweydManaf commented 1 week ago

useJsApiLoader

Just change the way you load the api.

Use this:

import {useJsApiLoader} from "@react-google-maps/api";

const {isLoaded, loadError} = useJsApiLoader({ id: 'google-map-script', googleMapsApiKey: YOUR_GOOGLE_MAPS_KEY, });

when you use hooks the component must be client. how to protect the api key?

JustFly1984 commented 1 week ago

you are setting CORS in google api console per key. so basically limit the key to your domain name