I have Get Locations module enabled, and I would like to output the coordinates of a given location as a separate field (longitude, latitude) when displaying a given node.

Somehow like this:
GPS: 45° 59' 45.24" N, 18° 40' 47.28" E

What's the best solution to do this?
Should I use Display Suite + "Add a code field" or is there a better solution?

3 Answers 3


Check out the geofield module. Even the Get Locations module supports it.

  • Thanks for your answer, but why should I install it beyond having Get Locations module enabled? Get Locations stores lat/lon data, I just would like to "extract" that, and output it as a separate field. Isn't it an "overkill" to enable another module for that? BTW, do you think Geofield module has any advantages over Get Locations? Feel free to comment it here: drupal.stackexchange.com/questions/39735/…, it would be great to read a little comparison regarding these modules. Thanks! (+1)
    – Sk8erPeter
    Sep 29, 2012 at 17:35

Get Geolocations seems to have support for Views.

If you add a view can't you add a field with the geolocation info and display them as lat/lon?

  • yes, but as I wrote, I have to display this information when displaying a given node, so in the regular node display mode, as a separate field with label, not in a view.
    – Sk8erPeter
    Sep 30, 2012 at 10:18
  • You could make a template for the node, or the field, and there, via php, get lat/lon, or include the view
    – arrubiu
    Sep 30, 2012 at 10:32
  • I was thinking about implementing hook_entity_view_alter() or another hook to make it look nice and easily modifiable, but I don't know what would be the nice solution for that - that's why I'm asking. :)
    – Sk8erPeter
    Sep 30, 2012 at 12:58
  • I think that a good solution is to add a tpl for the field.
    – arrubiu
    Oct 1, 2012 at 6:35

Finally, I solved it with creating a custom Display Suite field, which can be dragged on the admin interface similar to "regular" fields.
I can suggest this article for quick understanding: http://previousnext.com.au/blog/creating-custom-display-suite-fields-or-how-i-learned-stop-worrying-and-use-hookdsfieldsinfo

To get the necessary data from the field, I used field_get_items() like this article suggests (this is a must-read!): http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way

This is how I created my custom Display Suite field for getting GPS data from the Get Locations field:

 * Implements hook_ds_fields_info().
 * @see http://drupalcontrib.org/api/drupal/contributions!ds!ds.api.php/function/hook_ds_fields_info/7
function TESTMODULE_ds_fields_info($entity_type) {
  $fields = array();

  $fields['node']['MYNODETYPE_gps'] = array(
    // title: title of the field
    'title' => t('GPS'),
    // type: type of field
    // - DS_FIELD_TYPE_FUNCTION   : calls a custom function.
    'field_type' => DS_FIELD_TYPE_FUNCTION,
    // ui_limit : only used for the manage display screen so
    // you can limit fields to show based on bundles or view modes
    // the values are always in the form of $bundle|$view_mode
    // You may use * to select all.
    // Make sure you use the machine name.
    'ui_limit' => array('MYNODETYPE|*'),
    // function: only for DS_FIELD_TYPE_FUNCTION.
    'function' => 'TESTMODULE_MYNODETYPE_ds_field_gps',

  if (isset($fields[$entity_type])) {
    return array($entity_type => $fields[$entity_type]);
  return array();

 * Generate GPS coordinates as a DS field
 * Example: 46° 2' 27.24" N 18° 40' 37.2" E
function TESTMODULE_MYNODETYPE_ds_field_gps($field, $title = NULL){
  $output = '';

  // http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way
  // instead of the ugly $on_the_map_getlocations_field_data = $field['entity']->field_MYNODETYPE_on_the_map['und'][0];
  $on_the_map_getlocations_field = field_get_items('node', $field['entity'], 'field_MYNODETYPE_on_the_map');

    $on_the_map_getlocations_field_data = $on_the_map_getlocations_field[0];

    if(isset($on_the_map_getlocations_field_data['latitude']) && isset($on_the_map_getlocations_field_data['latitude'])){
      $output .= theme('getlocations_latitude_dms', $on_the_map_getlocations_field_data);
      $output .=  ' ';
      $output .= theme('getlocations_longitude_dms', $on_the_map_getlocations_field_data);

  return $output;

That's all!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.