I'm trying to access location data using the php parsing but I seem to be having no luck I've tried using the syntax shown in template and that doesn't return anything I've tried all sorts of others from examples here and in other nodes. I did the node declare

  global $form_values;
  $node = (array)$form_values;

and then have tried

  $node->locations[0]['city']
  $node['locations']['city']
  $node['locations'][0]['city']
  $locations[0]['city']

Could anyone help please? TIA

Comments

mydllurth’s picture

I'm having issue with this combination, but I am successful toward generating a title from locative fields. The following code snippet does work, but the node title is incomplete until I submit the node a second time. I only have "$zip :" as title on the first pass. I have only locations in the US, so the "us-" component of province is not used; only the two-letters state code is relevant.

The gmap API seems to require prior submission. We could peruse there for refinement of procedure and PHP code.

<?php
  global $form_values;
  $node = (array)$form_values;
  $loci = $node['locations'][0];
  $zip = $loci['postal_code'];
  $street = $loci['street'];
  $city = $loci['city'];
  $state = substr($loci['province'], -2);
  if($street) {
    $output = "$zip : $street";
  } else {
    $output = "$zip : $city $state";
  }
  print $output;
?>
mydllurth’s picture

I actually found my solution in the location API. The function is slted for deprecation, and seems off-topic here, but I'll post my finding.

After copying my loci array from $node['locations'][0], I defined one array element to reflect my site configuration, and made one location API call.


  $loci['country'] = 'us';
  $loci = location_get_postalcode_data($loci);

My automatic nodetitles implementation is happy.

--
A.D.G.

Sinovchi’s picture

You can use:
$node->field_lonlat[0][city]

It is working without problem

manish-31’s picture

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