Google Static Maps in a feed: Referer problem

Automated disclaimer: This post was written more than 15 years ago and I may not have looked at it since.

Older posts may not align with who I am today and how I would think or write, and may have been written in reaction to a cultural context that no longer applies. Some of my high school or college posts are just embarrassing. However, I have left them public because I believe in keeping old web pages aliveā€”and it's interesting to see how I've changed.

I've successfully embedded Google Static Maps in an RSS feed that I'm working on, and it displays great in standalone feed readers. Unfortunately, if someone tries to subscribe to my feed using a web-based reader/aggregator (such as Google Reader), my images don't show up. Presumably, the referer of the aggregator website is sent to maps.google.com, which rejects the request as not matching my API key.

Is there some trick I can use to make this work? Here are the options I can imagine:

  • Have the feed pull images from geohash.info, which in turn downloads the real image file and caches it
  • Again, have the images come from geohash.info, but this time have the page act as a non-caching proxy for maps.google.com (but setting a far-future expiration)
  • Trick the browser into sending geohash.info as a referer
  • Serve a different version of the feed to aggregator bots (based on their referer), using their API key (I don't know how I'd get that)
  • Have the image URLs point to a page at geohash.info that grabs the API key for the referer, and redirects to the maps.google.com URL using that API key (again, probably not an option)

Update a few hours later: That last approach worked! I found a way to look up the API key for any site, so now I can embed key-less static maps, like this:

<img src="https://lab.brainonfire.net/staticmap/redirect.php?path=rgba:0xff000088,weight:3|38,-78|39,-78|39,-79|38,-79|38,-78&size=400x400&mapType=mobile&markers=38.5017840,-78.1143706,red" alt="Example static map" />

(Update 2022-03-27: During blog maintenance, noticed this staticmap was no longer working; Google doesn't support this approach any more, and my lab server no longer serves these images. Changed to just show the HTML instead of embedding the image.)

Responses: 6 so far Feed icon

  1. Mark says:

    Hi,

    I love your idea for using a redirect to make static maps work in rss aggregators. I wrote my own php redirect script to do this, however my static maps still don't display in google reader.

    How exactly did you do your redirect?

    Any help you could offer would be much appreciated.

  2. Mark says:

    Oh, taking a closer look at your post I see that you 'look up the API key for any site'. How do you do this?

  3. Tim McCormack says:

    @Mark: Here is the API key URL for NewsGator: http://www.google.com/maps/api_signup?url=http%3A%2F%2Fwww.newsgator.com%2F (For example.)

    For a while I had a PHP script that would automatically grab that page and parse it whenever I saw a new referer, but Google soon put a stop to it. :-(

    I was able to contact someone at Google about the issue, and she said they were looking into removing the referer check... but that was a while ago, and I haven't seen any changes.

    For now I just serve up an alternate image to people who have unknown referers. The image explains the referer problem.

  4. Mark says:

    Ah, I see.

    So, I could get the API keys for a few common aggregators and do the redirect trick for those?

  5. Tim McCormack says:

    @Mark: My current database of keys should get you started.

  6. Mark says:

    Thanks so much, Tim. I'll give it a go.

Self-service commenting is not yet reimplemented after the Wordpress migration, sorry! For now, you can respond by email; please indicate whether you're OK with having your response posted publicly (and if so, under what name).