SupportObjective
ColdFusion Consulting, Support and Sales

If you want your code to work across multiple domains when using Google Maps you will need to dynamically change your Google Maps key based on request. Google requires you have a unique key for each host that makes calls into Google.

I solved this by placing a few statements in my application.cfc onrequest function.

The code checks the cgi.http_host and then sets the correct key value.

I created the all the keys at http://code.google.com/apis/maps/signup.html

view plain print about
1<cfif findnocase("123.com", cgi.HTTP_HOST) GT 0>
2 <cfset ajaxparams['googlemapkey'] = 'actual key from google'>
3</cfif>
4<cfif findnocase("345.com", cgi.HTTP_HOST) GT 0>
5 <cfset ajaxparams['googlemapkey'] = 'actual key from google'>
6</cfif>
7<cfif findnocase("567.com", cgi.HTTP_HOST) GT 0>
8 <cfset ajaxparams['googlemapkey'] = 'actual key from google'>
9</cfif>
10<cfajaximport params="#ajaxparams#">

If you just have one host you can alternatively set the key inside the administrator.

TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
The latest version of the maps API has removed the requirement for an API key. Even more easy! :)
# Posted By Jake Munson | 11/18/10 3:23 PM
Thank goodness. Is that version 3 or later3
# Posted By Mike Collins | 12/18/10 10:16 AM