The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Google Maps Cockup

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Obie Fernandez

Posts: 608
Nickname: obie
Registered: Aug, 2005

Obie Fernandez is a Technologist for ThoughtWorks
Google Maps Cockup Posted: Feb 14, 2007 11:07 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Obie Fernandez.
Original Post: Google Maps Cockup
Feed Title: Obie On Rails (Has It Been 9 Years Already?)
Feed URL: http://jroller.com/obie/feed/entries/rss
Feed Description: Obie Fernandez talks about life as a technologist, mostly as ramblings about software development and consulting. Nowadays it's pretty much all about Ruby and Ruby on Rails.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Obie Fernandez
Latest Posts From Obie On Rails (Has It Been 9 Years Already?)

Advertisement

Thanks to some priceless help from my friend Sebastian I got to the bottom of a serious Google Maps cockup (pardon the term). In order to use Google Maps in your web application you have to go procure a key. On that page, Google tells you that:

A single Maps API key is valid for a single "directory" on your web server, so if you sign up for the URL http://www.mygooglemapssite.com/mysite, the key you get will be good for all URLs in the http://www.mygooglemapssite.com/mysite/ directory.
An extremely common complaint (just do a Google search for "GMap subdirectory" or something along those lines...) is that you need a unique key for each directory of your URL
Oh, and one more thing?the fact that the Google Maps API key only works for a specific directory, and not any of its subdirectories, drove me up the wall. Instead of generating a key for meyerweb.com that would cover anything I might do on the site, I?ll have to generate a new key for every new directory. This is why I set up the directory /eric/tools/gmap/, but that just seems so? confining. Similarly, it was annoying that the key was completely bound to the full address. I generated the key for meyerweb.com/eric/tools/gmap/, so if anyone types in www.meyerweb.com/eric/tools/gmap/ they?ll get a key error. It would be nice if at some future time the keys were a little more flexible than they are now.
Sounds pretty stupid, right? The team that was in here before me said that indeed you need a unique key for each "subdirectory" of a given URL and wrote a Rails helper method to pull up one (of many registered keys) as needed for the various servers that we use, and each controller in the application. One of my first moves when I got here was to make everything REST resources, which had the unfortunate effect of creating many different "directories" in our URLs... thousands upon thousands of them. That of course presented a problem as far as the embedded Google Maps we have on those pages -- each would need its own registered API key!!! I saw the problem with my own eyes. Non-registered URLs would throw up an alert error box and not display the map.

Lesson Learned: If something sounds stupid, question it relentlessly!

After discussions of setting up an automatic key registration system and storing them in the database, I solved our problem another way -- embed the map in an IFRAME so that it's always coming from the same URL, hence only one key needed. However, I admit it's a bit of a hack.

All's been good for the last couple of weeks until I asked Sebastian if he also uses an IFRAME on streeteasy.com. He swore up and down that you absolutely only need ONE key per host. Actually, YOU ONLY NEED ONE KEY PER DOMAIN!

I went back and looked at the aformentioned application_helper code that does the key lookup. Guess what? It was implemented with the assumption that you needed a key per URL directory segment, so when you used an arbitrary URL that wasn't in its key hash, it returned a nil key string! For fuck's sake... I changed it to key off of only the hostname, and presto, it worked like magic. No IFRAME needed.

Given my good Google mojo, hopefully this story will save other schmucks some time in the future. :)


Tired of your job? Need to hire developers? Visit DZone Jobs: great people, great opportunities.

Read: Google Maps Cockup

Topic: Headed to RailsConf 2007 Previous Topic   Next Topic Topic: California Schemin': Ideas for Ruby 2.0

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use