This is not an issue, but a polite request for help. Location works just fine for me.

I have the Location and the User Locations module turned on and the geolocating works just fine.
I want to print the user location fields from the $user object into another node that is being accessed by the user.
I know that this data is in the user array but with my limited skills, I do not know how to access this and retrieve it.

This code (found here http://drupal.org/node/403594) :

<?php
global $user;
$viewinguser = user_load(array('uid' => $user->uid));
print_r($viewinguser);
?>

will print out the information below when placed in a node.

stdClass Object ( [uid] => 1 [name] => admin [pass] => 7f9183e3e1d1c5e45cb912076c6e3059 [mail] => john@test.ca [mode] => 0 [sort] => 0 [threshold] => 0 [theme] => [signature] => [signature_format] => 0 [created] => 1247602335 [access] => 1254367892 [login] => 1254357433 [status] => 1 [timezone] => -25200 [language] => [picture] => [init] => john@test.ca [data] => a:1:{s:13:"form_build_id";s:37:"form-5689e0bb8b10494a55af7d43997335e8";} [timezone_name] => [form_build_id] => form-5689e0bb8b10494a55af7d43997335e8 [roles] => Array ( [2] => authenticated user ) [locations] => Array ( [0] => Array ( [lid] => 3 [name] => [street] => 1000 Granville Street [additional] => [city] => Vancouver [province] => BC [postal_code] => [country] => ca [latitude] => 49.279232 [longitude] => -123.123041 [source] => 3 [is_primary] => 0 [province_name] => British Columbia [country_name] => Canada ) ) [location] => Array ( [lid] => 3 [name] => [street] => 1000 Granville Street [additional] => [city] => Vancouver [province] => BC [postal_code] => [country] => ca [latitude] => 49.279232 [longitude] => -123.123041 [source] => 3 [is_primary] => 0 [province_name] => British Columbia [country_name] => Canada ) )

So, I wish to grab the user's [latitude] and [longitude] fields and print them into another node. I am pretty lost here. I have seen other snippets of code that indicate that this is as simple as this:
<?php print $account->locations['0']['latitude'] ?>
But alas, this approach is not working.

I posted into a general form last night http://drupal.org/node/592754 making the same request. Sorry for the double post.
Any help that you could give me would be greatly appreciated. I thought this might be as simple as pulling data from the user profile, but there is more to it than that.

Comments

jereoms’s picture

Don't know if you solved this yet. But I was working on the same issue and now have it working. I used

  print $viewinguser->locations[0][latitude] 

Notice using the $viewinguser variable instead of $account which is what you are loading the data into.

dadderley’s picture

Thank you very much.

<?php
global $user;
$viewinguser = user_load(array('uid' => $user->uid));
$viewerlat=$viewinguser->locations[0][latitude];
$viewerlong=$viewinguser->locations[0][longitude];
print "viewers latitude ";
print $viewerlat;
print "<br />";
print "viewers longitude ";
print $viewerlong;
?>
nickl’s picture

Status: Active » Closed (fixed)

Support request complete.

fehin’s picture

Subscribing