How to get origin coordinates from current user’s Geofield field in proximity filter in views

Created on 18 October 2023, about 1 year ago
Updated 20 October 2023, about 1 year ago

Problem/Motivation

I’m trying to create a view that the current user can use to search/view users within a distance from the location on the current user’s profile. Every user’s location is collected on their profile with the Address field module which is then geocoded to a Geofield field. I want the views Geofield proximity filter origin coordinates to be from this Geofield field and the form to enter coordinates be hidden. The current user only has to change the distance length.

I have been searching and I can’t find a way to do this. Please help.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Needs review

Version

1.55

Component

Documentation

Created by

🇺🇸United States fehin

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @fehin
  • Status changed to Needs review about 1 year ago
  • 🇮🇹Italy itamair

    @fehin ... it looks to me that this previous existing issue (yet containing both "proximity" and "filter" in its title) would help you with the proper approach: https://www.drupal.org/project/geofield/issues/3211644 Allow setting proximity exposed filter manual origin default value with context tokens for more dynamic views Closed: works as designed

    And more specifically this comment of mine should redirect to the parent one: https://www.drupal.org/project/geofield/issues/3211644#comment-14091046 Allow setting proximity exposed filter manual origin default value with context tokens for more dynamic views Closed: works as designed

    It looks to me you should apply the same approach described there but at the user entity (instead of the node one).

    And it looks the views_argument_token has now direct support for Drupal 10 ...

    All sufficiently clear on this?

  • 🇺🇸United States fehin

    Thank you for your response. I have tried the Views Token module, but I don't know how to use it. I have a "user ID" contextual filter that I use to exclude the current user from the search result. If I add the Geofield proximity and use a token for the default value, how do I set up the URL for this second contextual filter? I currently have my URL like this user/%user/profile-search. Do I need to add anything to the URL for the Geofield proximity token to work? Also, I noticed the distance is added to the token ([user:field_user_geofield:lat],[user:field_user_geofield:lon]<=25mi) but I want to expose the distance so people can adjust it to their preference.

    I have attached images of how I currently have my views set up. It does not work properly, it returns all users, even those without Geofield.

Production build 0.71.5 2024