Calculating distance between two node references in Views (D6)

Events happening in the community are now at Drupal community events on www.drupal.org.
joaomachado's picture

Using Gmap, and Location and Views in D6.. So I have two node types both with locations. One node is factorys and the second is dealers for arguments sake. I then have another node type called "special" which has node reference fields to those nodes.

I created a view with that pulls the fields from the Special node type and want to display the distance between the two...not sure how to go about it?

John

Comments

Custom module

raintonr's picture

To modify the contents of a views table before it is rendered do this:

Create a custom module with a function called template_preprocess_views_view_table__yourviewname. Where yourviewname is... erm... your view name. Note the double underscore there.

This takes a single argument &$vars

$vars['rows'] holds the data collected by the view. Your function can use location information you should tell the view to fetch (but not display) to perform any calculations. You should probably place a dummy column (using NID or something) in the view and then have the calculated value put in that column.

When your function has done modifying the $vars variable call the standard hander to complete the job:

  /* Usual Views formatting */
  template_preprocess_views_view_table($vars);

This is way over my head

joaomachado's picture

This is way over my head raintonr...I am more of a point and shot developer not so much click and code ;-)

But I suppose I have to learn somehow, I will analyze your comment one word at a time.

Thank you!

Joao

@raintonr - this sounds

tinem's picture

@raintonr - this sounds really interesting. Would it be possible to see where you have used it showing us the map, please? I'm interested in everything that has to do with maps in Drupal. :-)

Not in maps, but...

raintonr's picture

I haven't used this particular function in mapping related things, but...

Have worked on a site that has a number of entries for 'challenges'. Each user can create any number of entries associated to the challenge, but only the users best attempt should be shown. We have a view that uses similar logic to that described to remove all but the best entry for each user.

Slightly OT, but if you like mapping stuff have a look here:

http://nobmob.com/node/12/tracks
http://nobmob.com/node/12/map

Location and Mapping

Group organizers

Group categories

Wiki type

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: