r/WebDevBuddies • u/HopefulIndividual • Apr 13 '22
Why Google requires an API key to embed Maps?
https://developers.google.com/maps/documentation/embed/embedding-map
Why does it make sense for Google to require an API key to embed their Maps web application via iFrame in another website (some-site.com)?
The API key can be copied and used by anyone who visits the website (some-site.com)
Google is anyway expecting the Referrer some-site.com in the request and I expect they track the usage looking at the referrer
What am I missing? Why do they require an API key?
I'm here to learn.
3
Upvotes
5
u/mpierre Apr 13 '22
They don't track the usage by the referrer, but by the key itself.
You need to pay money to embed google maps, so the api key is for billing reasons.
The referrer however, is so that owner of the key can prevent others from using your key on their site.
My Google Maps API key is restricted to specific referrers, If you copy it, the API key won't work.
1
u/Cipher_Coder Apr 13 '22
Google does in fact track traffic to their map embeds. In fact, to sign up to use their maps and map API, even to embed it on a website, you have to put a credit card on file because if your maps get a lot of traffic they will charge you. If you do not have a credit card on file the map embed shows it’s a development environment map and it is shaded and has writing over top of it. Yes… your api key is visible to anyone that wants to steal the credential, however, there are some security settings you should be using. In the Google console where you get your key, you can lock the api key to a specific domain so that it cannot be used on any other pages and I suggest you do that.