Tintef / react-google-places-autocomplete

React Google Places Autocomplete input -- fully customizable
https://tintef.github.io/react-google-places-autocomplete
MIT License
378 stars 162 forks source link

Google Maps JavaScript API has been loaded directly without loading=async #342

Closed kaloraat closed 3 months ago

kaloraat commented 10 months ago

I have been gettin this warning in console, anyone having the same issue?

Google Maps JavaScript API has been loaded directly without loading=async. This can result in suboptimal performance. For best-practice loading patterns please see https://goo.gle/js-api-loading

Screenshot 2024-01-30 at 11 08 11 AM
SiRoCu1976 commented 9 months ago

Add "loading=async" into your googlemap script tag.

This's solve for me.

JosueBCe commented 8 months ago

How to achieve that but without using an API key, just by putting the iframe and PB parameter?
<iframe class="d-block h-100" src='https://www.google.com/maps/embed?pb=@mapValue' callback="Function.prototype" style="border: 0; min-height: 300px;" allowfullscreen="" loading="lazy" title="Map"></iframe>

JosueBCe commented 8 months ago

Here's the solution in razor pages and piranha cms, where the pb is taken from the share>"copy html" code in google maps If you're using another framework or language, just focus in the js

image

` @if (!string.IsNullOrEmpty(Model.Map)) {

<script>
    async function loadMap() {
        const mapValue = '@Html.Raw(Model.Map)';

        const iframe = document.createElement('iframe');
        iframe.classList.add('d-block', 'h-100');
        iframe.src = `https://www.google.com/maps/embed?pb=${mapValue}`;
        iframe.style.border = '0';
        iframe.allowFullscreen = true;
        iframe.loading = 'lazy';
        iframe.title = 'Map';

        document.getElementById('mapContainer').appendChild(iframe);
    }

    window.addEventListener('load', async () => {
        await loadMap();
    });
</script>

} `

ashishFld commented 7 months ago

But what if we are using react-google-maps/api instead of script? Then what to do?

sebastian-meckovski commented 7 months ago

But what if we are using react-google-maps/api instead of script? Then what to do?

Replace import useLoadScript with useJsApiLoader in your import from "@react-google-maps/api";

BALBINOJLC commented 6 months ago

Estoy usando agm para cargar mis mapas y me aparece error ahora el mismo y no he podido resolverlo, alguien mas usa angular y me pueda ayudar?

codmitu commented 6 months ago

Estoy usando agm para cargar mis mapas y me aparece error ahora el mismo y no he podido resolverlo, alguien mas usa angular y me pueda ayudar?

add this to your index.html in the head tag

or

rodrigoqueiroz01 commented 5 months ago

if we are using angular js with angular-google-maps?

emaborsa commented 4 months ago

For who is working with React, follow this:

import { GoogleMap, useJsApiLoader } from '@react-google-maps/api';

const { isLoaded } = useJsApiLoader({
    id: 'google-map-script',
    googleMapsApiKey: "YOUR_API_KEY"
})
MarceRios commented 4 months ago

Para los que estamos usando @angular/google-maps como resolvemos este problema, he intentado con <script async src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"> y me sale este error Uncaught (in promise) InvalidValueError

Tintef commented 3 months ago

Doesn't seem to be an issue with this repos code, closing to keep issue neat and tidy.