How to get $node->locations[0]['latitude'] & $node->locations[0]['longitude'] for the node in CF?

Comments

stfb’s picture

Same problem.
I have a location field named "field_fd_plan".

When I put this in the computed field : $node_field[0]['value'] = $node->field_fd_plan[0][lid];
It works ! I get the location ID.
BUT
trying getting the name or latitude or whatever returns null.

This code is working ok if I put it in the node.tpl file :
print gmap_simple_map($field_fd_plan[0][latitude], $field_fd_plan[0][longitude], '', $field_fd_plan[0][name], 14, 'default', 'default', true, '' );

But if I put : $node_field[0]['value'] = var_export($node->field_fd_plan, TRUE);
on the CF i get this :
array ( 0 => array ( 'lid' => '1', ), )

Seems that all the informations but the lid disapeared !

How can I fix this ?
thanks ;-)

pvasili’s picture

sample code in the node-[type-of-node].tpl.php

.....
     $node = menu_get_object('node');

     $lat = $node->locations[0]['latitude'];
     $lon = $node->locations[0]['longitude'];
 
     if (((abs($lat)>=0)&&(abs($lat)<=90)) AND ((abs($lon)>=0)&&(abs($lon)<=180))) {
       $this_city = l("$node->page_title ( $node->title )", "node/$node->nid");
       $city_on_map = gmap_simple_map($lat, $lon, '', $this_city, 8, '530px', '350px', FALSE) ;
       print ("<h3>" . t('Location') . ":</h3>" . $city_on_map);
     }
  

....
print $content;
....
?>

stfb’s picture

In the status report section I had a warning about a database script update for the location module which has not been run.
After running it, still the same problem :-(

stfb’s picture

Some news.

What I'm trying to do :
I have a node which displays content in tabs. I use the tabs module.
I want to display a google map inside the "contact" tab.
To display the map, I've installed the gmap module + computed field module.
I've added a computed field to my content type which contains the google map code which displays the map.

The problem :
See #1

The solution:
I haven't figured out how to get those coordinates from inside computer field but I've found an other solution.
I now Use content-field-FIELDNAME-TYPENAME.tpl.php file.

Say, you have a location field named fd_plan using the content type test.
To display the map you just :
1- add a new file named content-field-fd_plan-test.tpl.php at the root of your theme dir
2- copy the content of content-field.tpl.php, that you find in modules/cck/theme inside this new file
3- add your gmap code in content-field-fd_plan-test.tpl.php just after "endforeach;?>" (you can put it where you want outside the foreach, this is for test purpose). The end of the file should look like this :

...
    endforeach;?>
    <?php
        print gmap_simple_map($items[0]['latitude'], $items[0]['longitude'], '', $items[0]['name'], 14, 'default', 'default', true, '' );      
    ?>
  </div>
</div>
<?php endif; ?>

It's not resolving the bug but I hope this will help people with the same problem.

Moonshine’s picture

Category: bug » support

Moving to support...

mmjvb’s picture

Issue summary: View changes
Status: Active » Closed (outdated)