<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blownpixel &#187; google</title>
	<atom:link href="http://www.blownpixel.co.uk/tag/google/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blownpixel.co.uk</link>
	<description>it&#039;s a design, tech, stuff thing..</description>
	<lastBuildDate>Wed, 05 Jan 2011 10:39:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>HOW TO: configure Google map application to select and use a valid API key when hosted behind multiple domains?</title>
		<link>http://www.blownpixel.co.uk/2010/06/how-to-configure-google-map-application-to-select-and-use-a-valid-api-key-when-hosted-behind-multiple-domains/</link>
		<comments>http://www.blownpixel.co.uk/2010/06/how-to-configure-google-map-application-to-select-and-use-a-valid-api-key-when-hosted-behind-multiple-domains/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 10:27:36 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://www.blownpixel.co.uk/?p=529</guid>
		<description><![CDATA[I had a client that had a .com and a .co.uk domain name both pointing to a single hosted website. Having previously only had the .co.uk domain name I had only included an api key for that domain]]></description>
			<content:encoded><![CDATA[<p>I had a client that had a .com and a .co.uk domain name both pointing to a single hosted website. Having previously only had the .co.uk domain name I had only included an api key for that domain.</p>
<p>When the site was displayed using the .com domain it threw up an invalid api key error.</p>
<p>Here is the fix:</p>
<p>Some applications may be hosted on multiple domains. For example, many content management systems push the same content to different domains (e.g.example.com and example.net) and wish to have that content single-sourced. Since Google Maps API keys are generated per domain, you&#8217;ll need to generate separate keys for each domain and configure your application to use the correct one. The easiest way to do this in JavaScript is to dynamically generate the 
<div class="codesnip-container" >&lt;script&gt;</div>
<p> tag using 
<div class="codesnip-container" >document.write</div>
<p> and assigning the correct domain-specific key within the src attribute&#8217;s URL as a parameter. In doing so, you&#8217;ll need to pre-generate and hardcode the list of keys within your application.</p>
<p>Create an object which contains a mapping between domain names and its corresponding Google Maps API keys. Use 
<div class="codesnip-container" >window.location.host</div>
<p> to retrieve the domain name your application is running against, and pass it into the object to select the appropriate key.</p>
<p>Below is a JavaScript snippet you can copy and paste into your application. Replace property names labeled 
<div class="codesnip-container" >domain*.com</div>
<p> on the left with your list of domains and assign to each entry its corresponding and unique Google Maps API key.</p>
<div class="codesnip-container" >
<div class="javascript codesnip" style="font-family:monospace;">document.<span class="kw1">write</span><span class="br0">&#40;</span><span class="br0">&#91;</span><br />
&nbsp; <span class="st0">&#8216;&lt;script src=&quot;http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;key=&#8217;</span><span class="sy0">,</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="st0">&#8216;domain1.com&#8217;</span><span class="sy0">:</span> <span class="st0">&#8216;apikey1&#8242;</span><span class="sy0">,</span><br />
&nbsp; &nbsp; <span class="st0">&#8216;domain2.com&#8217;</span><span class="sy0">:</span> <span class="st0">&#8216;apikey2&#8242;</span><span class="sy0">,</span><br />
&nbsp; &nbsp; <span class="st0">&#8216;domain3.com&#8217;</span><span class="sy0">:</span> <span class="st0">&#8216;apikey3&#8242;</span><span class="sy0">,</span><br />
&nbsp; &nbsp; <span class="st0">&#8216;domainN.com&#8217;</span><span class="sy0">:</span> <span class="st0">&#8216;apikeyN&#8217;</span><br />
&nbsp; <span class="br0">&#125;</span><span class="br0">&#91;</span>window.<span class="me1">location</span>.<span class="me1">host</span><span class="br0">&#93;</span><span class="sy0">,</span><br />
&nbsp; <span class="st0">&#8216;&quot; type=&quot;text/javascript&quot;&gt;&lt;<span class="es0">\/</span>script&gt;&#8217;</span><br />
<span class="br0">&#93;</span>.<span class="me1">join</span><span class="br0">&#40;</span><span class="st0">&#8221;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>When using the snippet above, be sure to include it within your HTML document above any script tags or JavaScript containing references to Google Maps API objects.</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'HOW TO: configure Google map application to select and use a valid API key when hosted behind multiple domains? on blownpixel',url: 'http://www.blownpixel.co.uk/2010/06/how-to-configure-google-map-application-to-select-and-use-a-valid-api-key-when-hosted-behind-multiple-domains/',contentID: 'post-529',code: 'Coco0043',suggestTags: 'Design,Featured,google,Web',providerName: 'blownpixel',styling: 'full' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.blownpixel.co.uk/2010/06/how-to-configure-google-map-application-to-select-and-use-a-valid-api-key-when-hosted-behind-multiple-domains/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

