You are here

function search_api_location_plugin_exposed_form::exposed_form_submit in Search API Location 7

This function is executed when exposed form is submited.

Parameters

array $form: Nested array of form elements that comprise the form.

array $form_state: A keyed array containing the current state of the form.

array $exclude: Nested array of keys to exclude of insert into $view->exposed_raw_input.

Overrides views_plugin_exposed_form::exposed_form_submit

File

includes/search_api_location_plugin_exposed_form.inc, line 136

Class

search_api_location_plugin_exposed_form
The search_api_location plugin to handle radius exposed filter forms.

Code

function exposed_form_submit(&$form, &$form_state, &$exclude) {
  $view = $this->view;
  $filter = $view->filter['radius'];
  $identifier = $filter->options['expose']['identifier'];
  $values = $form_state['values'];
  $gmap_key = variable_get('googlemap_api_key', '');
  if ($values[$identifier]['address'] && !empty($gmap_key)) {
    $url = url('http://maps.google.com/maps/geo', array(
      'query' => array(
        'q' => $values[$identifier]['address'],
        'key' => $gmap_key,
      ),
    ));
    $request = drupal_http_request($url);
    if ($request->code == '200') {
      $data = drupal_json_decode($request->data);
      if ($data['Status']['code'] == '200' && !empty($data['Placemark'])) {
        $form_state['view']->exposed_data[$identifier]['locpick']['longitude'] = $data['Placemark'][0]['Point']['coordinates'][0];
        $form_state['view']->exposed_data[$identifier]['locpick']['latitude'] = $data['Placemark'][0]['Point']['coordinates'][1];
      }
    }
  }
}