google-mapsgoogle-maps-embed

Google Maps Embed call failing for queries with number signs / pound signs / hash tags


My application throws the error:

Google Maps Platform rejected your request. You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account

I've tried reproducing the bug with a variety of query strings. It appears that the only time that the query fails is when there's a # for a suite number or apartment number.

This works: https://www.google.com/maps/embed/v1/place?q=17426%20Northwest%20Fwy,%20Jersey%20Village,%20TX%2077040,%20USA&key=

This does not work: https://www.google.com/maps/embed/v1/place?q=951%20Interstate%20Hwy%2030%20#105,%20Rockwall,%20TX%2075087,%20USA&key=

A potential solution is that I omit the # tags and just use the Place IDs when I get the initial address.

That requires a huge code refactor, so I would really love not to.


Solution

  • The "#" reserved character is usually used as an anchor for linking subsections and is one of those special characters that should be encoded in URLs.

    Try this: https://www.google.com/maps/embed/v1/place?q=951%20Interstate%20Hwy%2030%20%23105,%20Rockwall,%20TX%2075087,%20USA&key=

    Refer to Google's documentation on URL encoding for more details.

    Hope this helps!