It would be very useful to have the ability create a view that filters results by the individual users locations.

Example:

- John logs in and sets his zip code

- There is a block for events with locations in the sidebar submitted by many other users

- John gets a list of closest events sorted by proximity to his predefined zip code

- All users have different results based on their locations

Thanks and please let me know if something like this already exists.

Comments

levelos’s picture

I have the same need on momhub.com and accomplished it like this:

  • Add a user field for postal code. You could enable locations for users as well, but we only wanted to use postal code.
  • Create a view and a proximity filter.
  • In the arguments handling code, add something like this <?php $view->filter[2][value] = "xxxxx"; >

    That should do it.

  • robomalo’s picture

    Thanks so much for sharing! I'll give it a try.

    wolfderby’s picture

    I'm trying to do this exact same thing except with a directory of other locations. I tired the above suggestion but with out any success. If you could provide more details or perhaps some suggestions it would be much appreciated! Thanks

    levelos’s picture

    Let me try and clarify. The filters have a zero based index, so the arguments code needs to match the proximity filter index. If you only have one filter, than the arguments code would be:

      global $user;
      $view->filter[0][value] = $user->postal_code; 
    

    Not 100% sure on the code for grabbing the users profile field, but it's similar to that. If you expose the filter, than the value you provide will be the default and users can change it.

    wolfderby’s picture

    Whoa sweet!!! I got it to work with the follow:

      global $user;
      $view->filter[0][value] = $user->location['postal_code'];
    

    Thanks a lot!

    wolfderby’s picture

    Any chance anyone would know how to geocode the zip ($view->filter[0][value]) to output a lat,long to center a gmap :D

    I know the location module has the api but I'm not sure how to do this.

    It'd be really awesome to return a gmap with numbered markers in the postal code search results.

    Watch out yelp.com haha

    Coyote’s picture

    It would be nice if there was an easy way to get the user's location data that they entered via the location module, and use it as a default on proximity searches.

    I already have my users entering in their zip code as location data in their profiles. I'd like to have location-related views that do proximity searches default to the current user's location.

    Does anyone know a good way to do this?

    Coyote’s picture

    Sorry.. to clarify, the location data is stored in cck nodes, and I'd like to be able to use exposed filters for the search, rather than arguments.

    zip code map’s picture

    Title: Use current user zip code for views.module proximity filter » US zip code map
    Category: feature » support

    I would recommend http://www.zipcodesmapped.com/ for any US zip code map.
    You can use this to find any US zip code maps. You can search by (City, State OR Zip). they have all the maps showing zip codes and major mile streets in all of the united states. The service is free. Search for five Digit Zip Code and find the Maps for all 50 states. A Free ZIP Code Finder which can do wonders for you.

    bdragon’s picture

    Component: Code » Data update

    Changing component.

    yesct’s picture

    bdragon, It looks like the original issue was addressed for the original poster.

    Add the data update is a duplicate of #175193: Zip code database out of date

    I'll mark this as closed. Please re-open if needed. Sorry for any confusion.

    [edited: I noticed the duplicate and edited my question.]

    yesct’s picture

    Status: Active » Closed (duplicate)