Tintef / react-google-places-autocomplete

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

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

Open kaloraat opened 5 months ago

kaloraat commented 5 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 4 months ago

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

This's solve for me.

JosueBCe commented 3 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 3 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 2 months ago

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

sebastian-meckovski commented 2 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 1 month 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 1 month 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 3 weeks ago

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