3

Modules in use:

  • Drupal 7.12
  • Views 3.3
  • Location 3.x-dev
  • (and lots more of course)

I have a pretty standard view which has a user entered proximity filter for distance from a zip code, used to shows stores near a certain location (your standard dealer/store locater search). I would like to add a calculated field (or something) to show how far each store is from the entered zip code. This field would only be used in the view, and would not need to get saved to the node it represents, since this distance will change depending on the entered zip code.

Can anyone point me in the right direction?

Thanks!

5

I guess I should have looked through the module better. Here's the answer (tip: it's built right in!):

  • Go to your view (it needs to be a node based view I think)
  • In the "fields" section choose "add"
  • In the search box type "distance" and then choose the "Location: Distance / Proximity" field
  • Choose miles or kilometers to suite your needs
  • Then choose "Use Distance / Proximity Filter" from the drop down list (assuming, like me, you have an exposed filter in your view for users to enter a distance and a zipcode)
  • Adjust the label if you'd like, then click "apply"
  • In the "sort criteria" section, choose "add"
  • In the search box type "distance" and then choose the "Location: Distance / Proximity" field
  • Then choose "Use Distance / Proximity Filter" from the drop down list (assuming, like me, you have an exposed filter in your view for users to enter a distance and a zipcode)
  • Choose descending (most likely, anyway) and if you want to expose it, then you can click that check box also

And that does it!

  • 1
    And how can I then display the distance? – user20828 Sep 9 '13 at 14:43
0

just add the "Location: Distance / Proximity" field to your view. That should show the distance from the selected location and either the current user or a specific location. The other answer is wrong... doesn't actually answer the question, just explains how to set up the view without showing each result's distance.

Also note this only works with Field display... beware of using Display Suite as it would require a complicated custom code field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.