I have created a view in hopes of creating a page for a location search. But it seems to be not working. It's definitely possible that I'm not doing it right but I think I have it right.

Ohh, it works when I don't have it the filter as "Exposed", but when I do have it "Exposed", it breaks. Here's my view:

$view = new view;
$view->name = 'location_search';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Location Search';
$view->core = 7;
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Location Search';
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'title' => 'title',
  'distance' => 'distance',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'title' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'distance' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
);
$handler->display->display_options['style_options']['override'] = 1;
$handler->display->display_options['style_options']['sticky'] = 0;
$handler->display->display_options['style_options']['empty_table'] = 0;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = 'Location';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['external'] = 0;
$handler->display->display_options['fields']['title']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['element_label_colon'] = 0;
$handler->display->display_options['fields']['title']['element_default_classes'] = 1;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Field: Location: Distance / Proximity */
$handler->display->display_options['fields']['distance']['id'] = 'distance';
$handler->display->display_options['fields']['distance']['table'] = 'location';
$handler->display->display_options['fields']['distance']['field'] = 'distance';
$handler->display->display_options['fields']['distance']['label'] = 'Distance';
$handler->display->display_options['fields']['distance']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['distance']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['distance']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['distance']['alter']['external'] = 0;
$handler->display->display_options['fields']['distance']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['distance']['alter']['trim'] = 0;
$handler->display->display_options['fields']['distance']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['distance']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['distance']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['distance']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['distance']['alter']['html'] = 0;
$handler->display->display_options['fields']['distance']['element_label_colon'] = 1;
$handler->display->display_options['fields']['distance']['element_default_classes'] = 1;
$handler->display->display_options['fields']['distance']['hide_empty'] = 0;
$handler->display->display_options['fields']['distance']['empty_zero'] = 0;
$handler->display->display_options['fields']['distance']['origin'] = 'tied';
$handler->display->display_options['fields']['distance']['units'] = 'mi';
$handler->display->display_options['fields']['distance']['postal_code'] = '55425';
/* Field: Location: Latitude */
$handler->display->display_options['fields']['latitude']['id'] = 'latitude';
$handler->display->display_options['fields']['latitude']['table'] = 'location';
$handler->display->display_options['fields']['latitude']['field'] = 'latitude';
/* Field: Location: Longitude */
$handler->display->display_options['fields']['longitude']['id'] = 'longitude';
$handler->display->display_options['fields']['longitude']['table'] = 'location';
$handler->display->display_options['fields']['longitude']['field'] = 'longitude';
/* Sort criterion: Location: Distance / Proximity */
$handler->display->display_options['sorts']['distance']['id'] = 'distance';
$handler->display->display_options['sorts']['distance']['table'] = 'location';
$handler->display->display_options['sorts']['distance']['field'] = 'distance';
$handler->display->display_options['sorts']['distance']['origin'] = 'tied';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'ams_location' => 'ams_location',
);
/* Filter criterion: Location: Distance / Proximity */
$handler->display->display_options['filters']['distance']['id'] = 'distance';
$handler->display->display_options['filters']['distance']['table'] = 'location';
$handler->display->display_options['filters']['distance']['field'] = 'distance';
$handler->display->display_options['filters']['distance']['operator'] = 'dist';
$handler->display->display_options['filters']['distance']['value'] = array(
  'latitude' => '',
  'longitude' => '',
  'postal_code' => '',
  'country' => 'us',
  'php_code' => '',
  'nid_arg' => '',
  'nid_loc_field' => 'node',
  'uid_arg' => '',
  'search_distance' => '100',
  'search_units' => 'mile',
);
$handler->display->display_options['filters']['distance']['exposed'] = TRUE;
$handler->display->display_options['filters']['distance']['expose']['operator_id'] = 'distance_op';
$handler->display->display_options['filters']['distance']['expose']['label'] = 'Zip Code';
$handler->display->display_options['filters']['distance']['expose']['operator'] = 'distance_op';
$handler->display->display_options['filters']['distance']['expose']['identifier'] = 'distance';
$handler->display->display_options['filters']['distance']['expose']['required'] = 1;
$handler->display->display_options['filters']['distance']['expose']['gmap_macro'] = array(
  'default' => '[gmap ]',
);
$handler->display->display_options['filters']['distance']['expose']['user_location_choose'] = array(
  'default' => FALSE,
);
$handler->display->display_options['filters']['distance']['origin'] = 'postal_default';

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'locations/search';

/* Display: Attachment */
$handler = $view->new_display('attachment', 'Attachment', 'attachment_1');
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'gmap';
$handler->display->display_options['style_options']['markertype'] = '';
$handler->display->display_options['style_options']['latfield'] = 'title';
$handler->display->display_options['style_options']['lonfield'] = 'title';
$handler->display->display_options['style_options']['markerfield'] = 'title';
$handler->display->display_options['style_options']['enablermt'] = 0;
$handler->display->display_options['style_options']['rmtfield'] = 'title';
$handler->display->display_options['style_options']['tooltipfield'] = 'title';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['displays'] = array(
  'default' => 'default',
  'page' => 'page',
);
$handler->display->display_options['inherit_exposed_filters'] = 1;
$translatables['location_search'] = array(
  t('Master'),
  t('Location Search'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('Items per page'),
  t('- All -'),
  t('Offset'),
  t('Location'),
  t('Distance'),
  t('Latitude'),
  t('Longitude'),
  t('Zip Code'),
  t('[gmap ]'),
  t('Page'),
  t('Attachment'),
);

Comments

jbehshad’s picture

Same issue. I am trying to make it work as a Contextual filter but have had not luck doing so. I have tried it as a regular filter and exposed filter too.

dandaman’s picture

OK, I've done a bit of debugging and this is what I found.

It works fine for me if the filter is not exposed. If it is exposed, this is what happens starting on Line 478 of location.views.inc:

    case 'tied':
      if (!empty($view->filter)) {
        foreach ($view->filter as $filter) {
          if ($filter->table == 'location' && $filter->field == 'distance' && $filter->options['relationship'] == $options['relationship']) {
            $filter_options = array_merge($filter->options, $filter->options['value'], $filter->value);
            if ($coords = location_views_proximity_get_reference_location($view, $filter_options)) {
              $coordinates['latitude'] = (float) $coords['latitude'];
              $coordinates['longitude'] = (float) $coords['longitude'];
            }
          }
        }
      }
      break;

The problem is the $filter->value variable in that array_merge() statement. When exposed, it looks like this:

Array
(
   [0] => Array
       (
           [postal_code] => 55425
           [search_distance] => 100
           [search_units] => mile
       )

)

Looking at the code down the road, it looks like it's not expecting the extra level with the array inside an array and would work if that wasn't there. Where is that coming from and what do we need to do to fix this? Thanks!

dandaman’s picture

Title: "Use Distance / Proximity Filter" Not Working? » "Use Distance / Proximity Filter" Not Working in when an Exposed Views Filter

updated the title to clarify that it's a Views-related issue.

K.MacKenzie’s picture

I am really excited to be posting this as I am fairly new to Drupal - (6 months) and this is the first contribution I am going to make to the community.

I believe I have a fix for your problem. I came across this problem myself and when searching for a solution this thread is all I could find.

By inspecting the form element using chrome I discovered the the filter type which I am using (and I believe you are too) is actually called latlon_gmap (not "tied"). (this is the filter that allows you to use a map to select a location to filter by). Currently in the location.views.inc file there is no case for latlon_gmap so I simply created one...

I inserted:


    case 'latlon_gmap':
        $coordinates['latitude'] = (float) $options['latitude'];
        $coordinates['longitude'] = (float) $options['longitude'];
      break;

right after:

    case 'static':
      $coordinates['latitude'] = (float) $options['latitude'];
      $coordinates['longitude'] = (float) $options['longitude'];
      break;

this is around line 475 of location.views.inc

After making this change my filter (when exposed) now works as intended.

If this solution isn't what you were looking for please say so and I will attempt to help you find yours, I believe I understand this part of the code now well enough to help.

dandaman’s picture

I don't think I'm using the "latlon_gmap" but you're probably right, it may not be the problem of the "tied" code either. I was trying to use "postal_default" as the filter and it works when the form is not exposed, but it breaks when the filter is "exposed". Thanks for the offer for help.

hellomobe’s picture

+1

rooby’s picture

Component: Code » Location_views

I have not been able to reproduce a problem.

I have imported the view from the original post (I changed only the node type filter to suit my node types) and it works.

Form the original post:

Ohh, it works when I don't have it the filter as "Exposed", but when I do have it "Exposed", it breaks

What do you mean by "breaks", do you get error messages, no results, incorrect results (if incorrect, how are they incorrect)?

Can you confirm the problem still exists in the latest views 7.x-3.x-dev and location 7.x-3.x-dev?

@Vandrico:
Thanks for catching that. That is actually a different problem to the problem in this issue, and it affects drupal 6 as well.
I have created a new issue for it at #1199910: Exposed proximity filter using gmap doesn't filter results

rooby’s picture

I know a while back I saw a problem similar to this, which was fixed by the commit at #1109240-7: exposed filter 'proximity' doesn´t work with latest VIEWS.
If you are using a location version from before that date (April 5th, 2011) then updating to the latest version will hopefully fix the problem.

Note that the symptoms of that bug was that the filter did not filter the results.

This could potentially be a duplicate of that issue.

dandaman’s picture

Status: Active » Closed (duplicate)

You're right, this was a duplicate. I updated the modules to newer versions and that fixed it. Thanks for your help.