You are here

function locationmap_admin_settings_validate in Location Map 8.2

Same name and namespace in other branches
  1. 7.2 locationmap.module \locationmap_admin_settings_validate()
  2. 7 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.admin.inc
Callback for admin settings page

File

./locationmap.admin.inc, line 141

Code

function locationmap_admin_settings_validate($form, &$form_state) {
  $config = config('locationmap.settings');
  if ($form_state['values']['address']) {
    if ($form_state['values']['address'] == $config
      ->get('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']['address']);
    if ($latlng) {
      list($lat, $lng) = $latlng;
      $form_state['values']['latitude'] = $lat;
      $form_state['values']['longitude'] = $lng;
    }
    else {
      switch ($form_state['values']['latitude']) {

        // 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']['latitude'] = '-46.0868686';
          $form_state['values']['longitude'] = '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']['latitude'] = $config
            ->get('latitude');
          $form_state['values']['longitude'] = $config
            ->get('longitude');
          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;
      }
    }
  }
}