2

I try to get a distance between cck location nodes / users but I didn't succeed at that point because the only avalaible views field to do that is "EMPLACEMENT : DISTANCE / PROXIMITY" which concerns node location or user location, not cck location field.

How to get that point ?

Regards, Yoann

3

Results may vary based upon your drupal version, but basically when you create a proximity filter:

enter image description here

the first option is "Node location" but when you click on that:

enter image description here

it will allow you to use a Location CCK field as well.

| improve this answer | |
  • Thanks for your answer. Ok for Location CCK field linked to nodes but it seems there is a problem with Location CCK field linked to users bacause the "Location to use" is not available for "User's Latitude / Longitude from views uid argument". Actually I added a location cck field to users and this field is only available through "node's Latitude / Longitude frow views nid argument". – yoannl Jan 27 '13 at 21:43
  • You must be on drupal 7 then, and I don't have an answer to that, for in drupal 6 land, you can't add cck fields to users :) Here we'd add a location field to a content profile node type and then could use that. – Jimajamma Jan 27 '13 at 22:02
  • Ok I found a way to use locationn cck field without node or user location. I did as you told me but I needed to add a PHP code to get the initial position of the current user. Now it works fine and I get the correct distances. Thanks for your answer. – yoannl Jan 28 '13 at 21:20
  • Glad I was able to help out a bit! You may want to post your code for others to follow. – Jimajamma Jan 28 '13 at 22:29
  • ok it's done. Hope it's useful. – yoannl Jan 29 '13 at 9:02
0

Here is the code I used in the "php code for latitue, longitude" origin section in the "Emplacement: Distance / Proximity field" views :

global $user;
global $databases;
$res = db_set_active('default');
$query1 = db_query("SELECT field_lien_adresse_utilisateur_target_id FROM
{field_data_field_lien_adresse_utilisateur} WHERE entity_id = :uid", array('uid' => $user->uid));
$results1 = $query1->fetchAll();
$query2 = db_query("SELECT field_adresse_utilisateur_lid FROM
{field_data_field_adresse_utilisateur} WHERE entity_id = :entity_id", array('entity_id' => $results1[0]->field_lien_adresse_utilisateur_target_id));
$results2 = $query2->fetchAll();
$query3 = db_query("SELECT latitude, longitude FROM {location} WHERE lid = :lid",
array('lid' => $results2[0]->field_adresse_utilisateur_lid));
$results3 = $query3->fetchAll();
$result['latitude'] = (float) $results3[0]->latitude;
$result['longitude'] = (float) $results3[0]->longitude;
return $result;

Then I got the latitude and longitude of the current user.

Hope it's useful.

| improve this answer | |

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.