Search code examples
google-maps-embed

Embed Google Maps without cookies


I'm trying to embed a Google Map in a way that does not use cookies, because of the EU cookie law.
I want to use the Embed API because it can display the place information (rating, directions button...).

I know the Maps JavaScript API does not use cookies and works through the domain maps.googleapis.com.
However, the Maps Embed API uses www.google.com, which sets a NID cookie.

If I try and replace the URL like so

<iframe
  width="600"
  height="450"
  frameborder="0" style="border:0"
  src="https://maps.googleapis.com/maps/embed/v1/place?key=MY_API_KEY&q=Space+Needle,Seattle+WA" allowfullscreen>
</iframe>

There's a 1s flash where it displays it properly but then there's the "Something's wrong" error overlayed.
In the console, this error is returned:

Google Maps JavaScript API error: UnauthorizedURLForClientIdMapError
https://developers.google.com/maps/documentation/javascript/error-messages#unauthorized-url-for-client-id-map-error
Your site URL to be authorized: https://maps.googleapis.com/maps/embed/v1/place?key=MY_API_KEY&q=Space+Needle,Seattle+WA

Is there a way to use the Embed API without cookies?


Solution

  • I have revisited this issue and I cannot reproduce the problem any longer. Tested with Brave (with Brave Shields down for the site) and Firefox (with disabled uBlock Origin extension).

    It seems at this moment https://www.google.com/maps/embed does not use any cookies by itself. If the client is fresh on your site and views a page with a Google Maps embed, there won't be any new cookies set for the domain google.com. However, because the embed is an iframe, in the inspection tool, you will see any other cookie you have because of your interaction with all the google.com services you use. But these ones the client already has and are not related to your embedded map or your site in general.

    This now means you can use the Google Maps embed code (obtained with Share) on a opt-in cookie restricted site with no problem.