Ive been trying to setup a view where the distance to users is stated.

There has recently been an update of geofield however I am having trouble with calculating the distances to users (only get a zero)

I have checked whether the users have points, which they do, and tried to create a relationship to the user id without results.

I am a newbee in views so every advice would be beneficial

  • 1
    according to drupal.org/node/1469956#comment-6761140 it should be working in the 7.x.2 branch of geofield. I haven't come across a tutorial or documentation on how to set it up but will try myself in the next few days – uwe Jan 5 '13 at 16:50
  • Ahh okay...Actually I don't think there is a problem with the program..I found that I am getting the wrong points from addressfield (a place in the pacific instead of the actual address), however I haven't figured out how to correct this problem. Any ideas? – Peter Budde Smidt Christensen Jan 5 '13 at 17:37
  • Could you share a tutorial once you had a look at it? – Peter Budde Smidt Christensen Jan 6 '13 at 17:27

MotoTribe's answer is basically correct, but you might want to use the dev release instead of the alpha release. We've had a few bug fixes in since then. We should probably do a new release soon.

Source: Geofield maintainer.

| improve this answer | |
  • This needs an update. The 2.0 release is from 2013-Sep-22. – Mike Gifford Oct 22 '13 at 12:42

See new documentation page for geofield that shows how to setup a basic proximity search (it is based on MotoTribe's answer, but with a bit more info)

As requested, some of the link content:


Required modules

You must download the latest modules. These instructions have been tested with the 'dev' versions of geocoder, geofield, and addressfield modules. I believe these modules have a dependency on geophp, maybe others, install any dependent modules that you are instructed to when installing. Make sure to download the 'dev' versions!


Setup your content type:

  1. Create a content type for whatever you want to locate (e.g. Dealers, Stores, etc)
  2. In manage fields: Add an addressfield field to the content type (use options as you see fit).
  3. In manage fields: Add a geofield field to the content type. When adding, make sure to select 'Geocode from another field' from the 'widget' dropdown! The geofield option are pretty straightforward, just make sure to select the addressfield field you created earlier for the 'Geocode from field' option.
  4. Now, create a few records with addresses using your new content type.

That was easy! Now, let's setup the view result...

Setup your views query:

  1. Create a view, can be any kind. Select the content type you created earlier for the results.
  2. Add a field: '[name of your geofield] - proximity' (there are a number of geocoding related fields, you want the one with '- proximity' appended)
  3. In the field settings: For the 'Source of Origin Point' field, select 'Exposed Geofield Proximity Filter'.
  4. Add any other identifying fields, such as title, address, etc.
  5. Add a new 'Filter Criteria' for your view for the '[name of your geofield] - proximity' field.
  6. Choose 'Expose this filter to visitors, to allow them to change it'
  7. For 'Operator', choose 'Is less than', because you want results that are closer than a certain distance from the value your users enters, e.g. less than 100 kilometers, etc.
  8. For 'Source of Origin Point', choose 'Geocoded Location', which will allow the user enter friendly values such as city, state, zip/postecode, state, etc. (basically, anything you can put into Google location searches).
  9. For Geocoding Service, choose 'Google Geocoder'.
  10. Add a Sort Criteria: '[name of your geofield] - proximity'. Also, remove any other sort filter already existing, since sorting by date first will foil your proximity filter!
  11. Set to sort ascending, since you probably want to show the closest results first.
  12. Set 'Source of Origin Point' to 'Exposed Geofield Proximity Filter'.
  13. Test your new proximity search!
| improve this answer | |
  • Thanks RR, very helpful. Instead of an exposed proximity filter, I'd like to have a user field that stores a proximity center point. I'm guessing that would require a contextual filter? Any suggestions appreciated. – Louis Apr 15 '13 at 18:48
  • I believe you should be able to use a contextual filter to achieve the same result. You would need to add the geofield to the User profile, since this is what you would use for the contextual filter value. – RogerRoger Apr 19 '13 at 15:44
  • @RogerRoger So we do not have to add the geofield itself in the view? I am using IPV&M, location, geofield and geocoder modules – Umair Oct 19 '19 at 15:45
  • 1
    HI @Umair, sorry, I haven't used these modules since 2013, so I'm not sure. As far as I can remember, at the time adding the geofield to the view wasn't necessary. – RogerRoger Oct 22 '19 at 12:02
  • @RogerRoger You are right. Geofield isnt necessary – Umair Oct 23 '19 at 15:47

Looks pretty straightforward using geofield 7.x-2.0-alpha2:

I assume you have geofield and geophp enabled and assume you have added a geofield to your users that get the location from an addressfield.

  1. create a view of type users
  2. add "[name of your geofield] - proximity" field
  3. select "source of origin", I tried "exposed geofield proximity filter", check the "round" box
  4. add "[name of your geofield] - proximity" exposed filter and select a "source of origin point" as well. For example, add a "geocoded location" (fancy word for address)
  5. add that same field to your sort options to sort by proximity as well.

In your example you would probably change the "source of origin point" to "current user".

| improve this answer | |

Juts in case, i wrote a little plugin, it works on the alpha2 release.

I provide a simple proximity filter that use the Smart IP location information (so Smart IP is requiered). User just have to chek a box to search around him. Nice, isn't it ?

Disclaimer : I provide this code as is, i'm not responsible, etc. ;) And i post this under the control of the Maintainers, who can tell me that this is a sh** if it is the case.

See this comment for complete instructions : http://drupal.org/node/1901750#comment-7191652

Best regards,

| improve this answer | |

In addition to RogerRoger's post:

In case you're using this as a Views attachment, don't forget to check "Inherit exposed filters" in the attachment settings, or it will only display the distance from the default value, or "0" in case there's no given default value.

| improve this answer | |

Your Answer

