Load googlemaps api from backend to avoid exposing key

Hi there,
I am using a custom JS code to display a map with various pointer and calculations thanks to a tutorial from @raydeck that has proven very useful

The current issue I am having is that I need to run the following JS commands on page load which expose my google API key:

doc = document.createElement(‘script’);
doc.src = ‘https://maps.googleapis.com/maps/api/js?key=[xxxx]&channel=1&sensor=false&libraries=geometry’;
document.body.appendChild(doc);

How could I convert the following function to request the script from the backend and hide the API key ?

Thanks in advance for your help

As far as I know this Google Maps key is a public key. Google gives you the possibility to restrict your key in their console. That’s the way to make sure your key isn’t abused.

1 Like

Thanks @andreas, that was easy enough :grinning:
That’s all fixed now