YM4R with multiple domains
Posted: March 2nd, 2009 | Author: Nick | Filed under: rails | Tags: google, googlemaps, rails, ym4r | No Comments »I didn’t find this option documented anywhere until I started digging through the code within the library. I had an instance where I was using A CMS to run multiple sites that all needed a use for google maps. With the regular implementation of YM4R you would normally get an error from google maps stating that this Google Maps API key isn’t valid for this domain. By simply passing in the host option you can then use the additional api keys you have setup in your config/gmaps_api_key.rb
In your config/gmaps_api_key.rb there needs to be a key for each domain that you wish to have google maps on.
production: host.com: longapikeythatmakesnosense anotherhost.com: jsdkfljskfljsgklsjgkl
Then in your layout file you need to print out the correct API key for communicating with google maps. This can be done by just passing in the host option with the request.host as it’s value.
< %= GMap.header(:host => request.host) %>
Follow me on Twitter