You are here

function locationmap_admin_settings_validate in Location Map 7

Same name and namespace in other branches
  1. 8.2 locationmap.admin.inc \locationmap_admin_settings_validate()
  2. 7.2 locationmap.module \locationmap_admin_settings_validate()

@todo Please document this function.

See also

http://drupal.org/node/1354

1 string reference to 'locationmap_admin_settings_validate'
locationmap_admin_settings in ./locationmap.module
Callback for admin settings page

File

./locationmap.module, line 168

Code

function locationmap_admin_settings_validate($form, &$form_state) {
  if ($form_state['values']['locationmap_address']) {
    if ($form_state['values']['locationmap_address'] == variable_get('locationmap_address', '')) {
      drupal_set_message('Address has not changed. In order to preserve any location marker fine-tuning, coordinates have not been updated.', 'status');
      return;
    }
    $latlng = locationmap_geocode_for_address_recursive($form_state['values']['locationmap_address']);
    if ($latlng != FALSE) {
      list($lat, $lng) = $latlng;
      $form_state['values']['locationmap_lat'] = $lat;
      $form_state['values']['locationmap_lng'] = $lng;
    }
    else {
      switch ($form_state['values']['locationmap_lat']) {

        // If Geocoding fails and there are no previous coordinates, set to the default: Round Island in New Zealand's Fiordland National Park.
        case '':
          $form_state['values']['locationmap_lat'] = '-46.0868686';
          $form_state['values']['locationmap_lng'] = '166.6822074';
          drupal_set_message('Unable to Geocode address provided. As no previous coordinates were recorded, default values have been inserted. Try slightly modifying the address and resubmit, e.g. giving more or less detail, such as leaving out the suburb or state.', 'warning');
          break;

        // If Geocoding fails and there are previous coordinates, set to those coordinates.
        default:
          $form_state['values']['locationmap_lat'] = variable_get('locationmap_lat', '-46.0868686');
          $form_state['values']['locationmap_lng'] = variable_get('locationmap_lng', '166.6822074');
          drupal_set_message('Unable to Geocode address provided—previous coordinates will be used. Try slightly modifying the address and resubmit, e.g. giving more detail, or leaving out the suburb or state.', 'warning');
          break;
      }
    }
  }
}