I could be doing this incorectly but I want to set a static value for lat lon for a proximity field in a my view.

I was hoping to pass in a token for lat, lon.

Is that possible?

Comments

SocialNicheGuru created an issue. See original summary.

SocialNicheGuru’s picture

Title: Allow tokens for lat lon in geolocation proximity field in a view » Allow tokens in views filter proximity for static and geocoded fields - allow to get proximity of current logged in user.
Component: Geolocation field » Geolocation Field / Backend

In the proximity filter for views
select static
it would be nice to then be able to enter in two tokens for lat/lon that represent the current location the logged in user is in.

Another option would be select the geocode from exposed fields options.
I could then put in a default token for the current address the person is at

That would cover the options of getting distance from the current logged in user depending

Ruslan Piskarov’s picture

Hello.
For such functionality, I am using the following code.

/**
 * Implements hook_views_pre_build().
 */
function MYCUSTOMMODULE_views_pre_build(ViewExecutable $view) {
  if ($view->id() == 'events' && $view->current_display == 'home_page') {

    $exposed_filters = $view->getExposedInput();
    if (!isset($exposed_filters['field_geolocation_proximity-lat'])
      && !isset($exposed_filters['field_geolocation_proximity-lng'])
    ) {
      if (\Drupal::moduleHandler()->moduleExists('smart_ip')) {

        /** @var \Drupal\smart_ip\SmartIpLocation $location */
        $location = \Drupal::service('smart_ip.smart_ip_location');

        if ($location->get('latitude') && $location->get('longitude')) {
          $exposed_filters['field_geolocation_proximity-lat'] = $location->get('latitude');
          $exposed_filters['field_geolocation_proximity-lng'] = $location->get('longitude');
          $exposed_filters['field_geolocation_proximity'] = 24898;
          $view->setExposedInput($exposed_filters);
        }
      }
    }

  }
}
ChristianAdamski’s picture

Status: Active » Fixed

You can use the new "Proximity Entity" argument introduced in #2936637: In "Filter Criteria" the "Proximity" filter does not work (v2) now. It allows to calculated the proximity by entity ID relative to any geolocation field in the current install. You can then use the "Current user ID" as fallback value in views then.

Status: Fixed » Closed (fixed)

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