Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kaloraat opened this issue Jan 30, 2024 · 11 comments
Closed

Comments

@kaloraat
Copy link

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
Copy link

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

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&loading=async&callback=initMap&v=weekly"></script>

This's solve for me.

@JosueBCe
Copy link

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
Copy link

JosueBCe commented Mar 28, 2024

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
Copy link

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

@sebastian-meckovski
Copy link

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
Copy link

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
Copy link

codmitu commented May 17, 2024

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

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&loading=async&libraries=YOUR_LIBRARIES&v=weekly"></script>

or

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&loading=async&callback=YOUR_initMap_FUNCTION&libraries=YOUR_LIBRARIES&v=weekly"></script>

@rodrigoqueiroz01
Copy link

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

@emaborsa
Copy link

emaborsa commented Jul 9, 2024

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
Copy link

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">
</script> y me sale este error Uncaught (in promise) InvalidValueError

@Tintef
Copy link
Owner

Tintef commented Aug 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests