I dont know if this is the right spot for this question. Does it make sense to support different Google Maps API keys for every subdomain from domain access?

Maybe the Gmap modules are a better place for implementing this. But on the other hand its too specific to solve it in a gereric way maybe.

I solved this problem for myself in my template file. It will work for the CCK Maps Module (http://drupal.org/project/cck_map) and has to be modified slightly to work with the Gmap module because the syntaxt that Gmap module uses is different:

$gmap_api_keys = array(
  'sub1.mydomain.com' => 'Here goes Google Maps API key for sub1',
  'sub2.mydomain.com' => 'Here goes Google Maps API key for sub2',
  'sub3.mydomain.com' => 'Here goes Google Maps API key for sub3',

// www. is removed with mod_rewrite in .htaccess
switch ($_SERVER['HTTP_HOST']) {
  case 'sub1.mydomain.com':
    $map_key = $gmap_api_keys['sub1'];

  case 'sub2.mydomain.com':
    $map_key = $gmap_api_keys['sub2'];

  case 'sub2.mydomain.com':
    $map_key = $gmap_api_keys['sub3'];

If ($map_key) { // if we have a matching key insert it
  $head = preg_replace("!(<script type='text\/javascript' src='http\:\/\/maps\.google\.com\/maps\?file=api&v=2&key=)(.*?)('><\/script)!", "$1$map_key$3",$head);
else { // if we have no key remove it to avoid alert errors
  $head = preg_replace("!(<script type='text\/javascript' src='http\:\/\/maps\.google\.com\/maps\?file=api&v=2&key=)(.*?)('><\/script)!", " ",$head);

print $head;

There is maybe a solution to alter static $stored_head in drupal_set_html_head (http://api.drupal.org/api/function/drupal_set_html_head/5) with a small module?

function drupal_set_html_head($data = NULL) {
  static $stored_head = '';

  if (!is_null($data)) {
    $stored_head .= $data ."\n";
  return $stored_head;
#9 gmap_domain.zip840 bytescreaoy
Members fund testing for the Drupal project. Drupal Association Learn more


derjochenmeyer’s picture

I forgot to mention. This code replaces <?php print $head; ?> in my page.tpl.php file.

And while modifying it for pasting it here i messed up the $gmap_api_keys array. Unfortunately i cant modify the issue to correct it:

$gmap_api_keys = array(
  'sub1' => 'Here goes Google Maps API key for sub1',
  'sub2' => 'Here goes Google Maps API key for sub2',
  'sub3' => 'Here goes Google Maps API key for sub3',
agentrickard’s picture

You have two options for best integration with Domain Access.

1) There already exists two hooks:


Using these hooks and a MENU_CALLBACK, you can create a GMap configuration page for each domain. This will appear as a link on the domain list screen.

You would need a module with the following functions:

domain_gmap_form() and it's associated form handlers.

hook_domainload() is used to append data to the $_domain global, so you can use the variables you need. See http://therickards.com/api/function/domain_user_domainload/Domain for example.

Alternately, these functions could be inserted into the Gmap module itself.

2) Write a small module that implements hook_form_alter() and adds the form element to the 'system_settings_form' as implemented by Domain Conf.

See http://therickards.com/api/function/domain_conf_form_alter/Domain

However, it may be best to include a domain module hook to let you add elements to this form.

For an immediate solution, use option #1.

agentrickard’s picture

Status: Active » Postponed (maintainer needs more info)

Do you want this data available in the $_domain global variable of in the site variable's $conf array?

See http://drupal.org/node/202917 for a similar request.

agentrickard’s picture

Status: Postponed (maintainer needs more info) » Fixed

hook_domainconf() implemented in HEAD. Your module would need a function similar to this:

function gmap_domainconf($domain) {
  $form['gmap_api_key'] = array(
    '#type' => 'textfield', 
    '#title' => t('Gmap API Key'), 
    '#default_value' => variable_get('gmap_api_key', ''), 
    '#size' => 30, 
    '#maxlength' => 255, 
    '#description' => t('API key to use for this domain.')
  return $form;

This will store and rewrite the variable for each site, so then you retrieve the value using variable_get('gmap_api_key', '').

fseto’s picture

oh wow! Thanks! I've been adding this manually in domain_conf.module for Picasa, but that gets to be a headache during upgrades. This will be nice.
In case anyone interested, here's the snippet for I use for Picasa:

      if (module_exists('picasa')) {
        $form['picasa_settings']['picasa_username'] = array(
          '#type' => 'textfield',
          '#title' => t('Your Picasa Web Username'),
          '#default_value' => variable_get('picasa_username', ''),
          '#size' => 70,
          '#maxlength' => 255,
          '#description' => t('The username you use at http://picasaweb.google.com/ to '.
          'view your Web Albums')

agentrickard’s picture

Right. To make the upgrade path smooth, you probably want to make a module called something like "domain_fseto" that includes all your custom hook implementations.

There is no way to include all these types of things into the Domain module core, so the hook is your best bet. These hooks can also, of course, be implemented in other modules. So the function picasa_domainconf() is the perfect solution.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

computer_jin’s picture

I try many times and register a new key for my site and i am getting this error " google map api used for this website registered for different website " From many days and i have post in many forums topics but no reply for that can any one is there who will tell me how to solve this issue .................................................

creaoy’s picture

840 bytes

Hope this will help

teagle’s picture

jk - YES IT DOES! Thank you very much!

creaoy’s picture

Version: 5.x-1.0rc1 » 6.x-1.0
Summit’s picture

Great if all domain modules would be shown in one place, may be a wiki or something. I miss overview now :)
greetings, Martijn