How to display a GMap from a referenced node?

tonycpsu - April 2, 2009 - 14:15

Background: I have the content types "Location" and "Event". Location just has location.module and GMap fields, Event has start and end times (CCK Date fields) and a CCK Node Reference field to refer to the Location node for where the event is being held.

What I'd like to do is, when I view an event, show a map of the event's location, following the CCK node reference field. This is very simple to do if the location fields are in the Event content type, but I can't figure out how to show a referenced Location node's map when viewing an Event. I thought contemplate might let me refer to these fields, but they don't show up in the "Body Variables" section, and so far I haven't figured out the right magic to get this to happen using Views.

Any help is much appreciated.

_

WorldFallz - April 2, 2009 - 14:29

I can think of 2 things. First, if you want to do with with contemplate, you'll have to do a node_load on the location node to be able to access the fields on the location. Second, you could do with a view by adding a relationship for the location nodereference field.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

Thanks for the tips. I did

tonycpsu - April 2, 2009 - 14:36

Thanks for the tips.

I did try to create a view using a relationship for the location node reference field, but couldn't get the map to display. What other fields do I have to add? I assume the view display style should be GMap, but do I also need to add a GMap field? Do I need any other arguments other than Node:nid? Nothing I've tried has worked.

I'll search the forum for examples of using node_load and contemplate.

_

WorldFallz - April 2, 2009 - 16:11

I just tried it with the views method. You have to use the location cck field (rather than the standard location form alter stuff).

I created a content type for "location" added a location cck field to it, then added a node reference field to that content type on the events content type. Then, when you create the view (a node view filtering for the event content type using one of the fields styles), you add the relationship for the location nodereference field, add the location cck field in the list of fields, and select the 'location' relationship. It will automatically display the location field with the gmap-- exactly as you have the location cck field configured to display on the location content type.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

Not quite there...

tonycpsu - April 2, 2009 - 18:16

Thanks again for your help.

I followed your instructions, and I got it to the point where it displays a gmap in the Event view, but the gmap doesn't have the marker at the location like it's supposed to -- t's just a blank map. I think it might have something to do with where the gmap field gets its location info from. There are two options "use Location" and "use CCK fields for lat/long" but it says the lat/long aren't supported. I have it set to "use Location" now, but my hunch is that means use the location.module fields, not the CCK location fields.

Were you able to get the Location node's marker to appear on the map when you tried this?

Edit: Actually, the marker doesn't even appear in the GMap field when I view the Location node instead of the Event node. So maybe this is a limitation of using Location CCK fields versus location.module?

Edit #2: "Add Markers" is checked in the field properties for the map field.

_

WorldFallz - April 2, 2009 - 19:08

hmm... I didn't have to do anything, the markers were already there. However, between the gmap and location modules there are a HUGE amount of options-- frankly I have no idea what I may have changed prior to creating this view. I did notice that the map settings were coming from the map settings available at admin/settings/gmap.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

No dice.

tonycpsu - April 2, 2009 - 21:05

I just can't get it going. I tried various versions of GMap, GMap Location, Location, GMap Field, etc. and couldn't get it working. The map shows up fine but it won't display the marker from coordinates in the CCK Location field. For now I guess I'll have to revert to storing the location info in the Event node itself unless anyone has any other suggestions.

Regardless, thanks much for helping.

_

WorldFallz - April 3, 2009 - 00:06

I'm not sure what it could be-- i'm using the dev versions of both gmap and location. You can see the view here: http://www.flickr.com/photos/9779490@N07/3407518381. The title and date fields are from the event content type and the location field is from the location content type via a nodereference field on the event content type.

Here's an export of the view (maybe compare to an export of yours):

$view = new view;
$view->name = 'events';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
  'field_location_nid' => array(
    'label' => 'location',
    'required' => 0,
    'delta' => -1,
    'id' => 'field_location_nid',
    'table' => 'node_data_field_location',
    'field' => 'field_location_nid',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'title' => array(
    'label' => 'Title',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
    ),
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
  'field_date_value' => array(
    'label' => 'Date',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
    ),
    'link_to_node' => 1,
    'label_type' => 'widget',
    'format' => 'default',
    'multiple' => array(
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_to' => '',
      'group' => TRUE,
    ),
    'repeat' => array(
      'show_repeat_rule' => '',
    ),
    'fromto' => array(
      'fromto' => 'both',
    ),
    'exclude' => 0,
    'id' => 'field_date_value',
    'table' => 'node_data_field_date',
    'field' => 'field_date_value',
    'relationship' => 'none',
  ),
  'field_ccklocation_lid' => array(
    'label' => 'Location',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
    ),
    'link_to_node' => 0,
    'label_type' => 'widget',
    'format' => 'default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_ccklocation_lid',
    'table' => 'node_data_field_ccklocation',
    'field' => 'field_ccklocation_lid',
    'relationship' => 'field_location_nid',
  ),
));
$handler->override_option('filters', array(
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'event' => 'event',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('title', 'Events');
$handler->override_option('style_plugin', 'grid');
$handler->override_option('style_options', array(
  'grouping' => '',
  'columns' => '1',
  'alignment' => 'horizontal',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'events');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
));

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

Trying a different approach.

tonycpsu - April 3, 2009 - 01:46

I'll try to compare those views and see what I find, but earlier tonight, in an effort to rule out some weird inconsistency on my site, I setup a new test site with just the minimum modules needed. Aside from the default/core modules, the only ones I've added so far are:

Content 6.x-2.x-dev
Geo Data 6.x-1.x-dev
Geo Field 6.x-1.x-dev
GMap 6.x-1.1-rc1
GMap Field 6.x-1.x-dev
Gmap Location 6.x-1.1-rc1
Location 6.x-3.1-rc1
Location CCK 6.x-3.1-rc1

I'm already stuck at just the Location node type. I've created it, added Location CCK and GMap fields, and I'm already not getting markers on the Location node view. Do you see the markers when you just view a Location node, not the event view? I'm thinking if I can't see markers on the Location node, I won't have any luck with seeing it from the view, either.

_

WorldFallz - April 3, 2009 - 03:09

Yep-- the marker shows on the location node, exactly how it does on the event node. One thing to note-- i'm only using the location and gmap modules (not geo field or any other geo module package).

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

Okay, I thought the Geo

tonycpsu - April 3, 2009 - 13:50

Okay, I thought the Geo modules were required to geocode lat/lon from addresses, but apparently not. I uninstalled those, but the problem persists. Now I'm completely stumped.

_

WorldFallz - April 3, 2009 - 15:00

If you want use my contact form and send me an email. I'll zip up my gmap and location module directories and email them to you (in case I applied some type of patch, i really don't remember anymore). Other than that i'm stumped as well-- you could try posting in the issue queue.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

AH HA... i think i found it.

WorldFallz - April 3, 2009 - 15:42

AH HA... i think i found it.

Replace the location.tpl.php file for the location module with this:

<div class="location vcard"><div class="adr">
<?php echo $name; ?>
<?php if ($street) {?>
<div class="street-address"><?php
 
echo $street;
  if (
$additional) {
    echo
' '. $additional;
  }
?>
</div>
<?php }?>
<?php
 
if ($city || $province || $postal_code) {
   
$city_province_postal = array();

    if (
$city) {
     
$city_province_postal[] = '<span class="locality">'. $city .'</span>';
    }
    if (
$province) {
     
$city_province_postal[] = '<span class="region">'. $province .'</span>';
    }
    if (
$postal_code) {
     
$city_province_postal[] = '<span class="postal-code">'. $postal_code .'</span>';
    }

    echo
implode(', ', $city_province_postal);
  }
?>

<?php if ($country_name) { ?>
<div class="country-name"><?php echo $country_name; ?></div>
<?php } ?>
<?php
 
// "Geo" microformat, see <a href="http://microformats.org/wiki/geo
" title="http://microformats.org/wiki/geo
" rel="nofollow">http://microformats.org/wiki/geo
</a>  if ($latitude && $longitude) {
    // Assume that 0, 0 is invalid.
    if ($latitude != 0 || $longitude != 0) {
?>

<div class="geo"><abbr class="latitude" title="<?php echo $latitude; ?>"><?php echo $latitude_dms; ?></abbr>, <abbr class="longitude" title="<?php echo $longitude; ?>"><?php echo $longitude_dms; ?></abbr></div>
<?php
   
}
  }
?>

<?php if ($map_link) { ?>
<div class="map-link"><?php echo $map_link; ?></div>
<?php } ?>
<?php if ($map) { ?>
<div class="map"><?php echo $map; ?></div>
<?php } ?>
</div></div>
?>

There's an issue in the location issue queue for missing gmaps-- I believe that's the problem. I just forgot I fixed it.

Let me know if that works.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

Epilogue: Worldfallz sent me

tonycpsu - April 3, 2009 - 18:51

Epilogue:

Worldfallz sent me older dev versions of GMap and Location that fix this problem. It would appear this is a known problem already in the Location issue queue, so I'm subscribing there and eagerly awaiting a fix. Until then, I should be able to get by with the older dev versions.

_

WorldFallz - April 3, 2009 - 19:11

Can you link the issue(s) you subscribed to? i searched for a bit and couldn't find one (other than the one I mentioned above which didn't end up solving your problem).

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

_

WorldFallz - April 3, 2009 - 19:23

Nevermind-- i found the issues by checking your tracker ;-).

I finally found a relevant issue, but now I'm more confused, lol. According to http://drupal.org/node/347091#comment-1223959, the fix to location.tpl.php should have fixed the issue for you. I'm not sure why you needed my entire gmap/location directories for it to work. I'm thinking ill have to test this a fresh site when I get a chance.

EDIT: nevermind2, I figured it out. In addition to the location.tpl.php file, there was a change to the theme function as part of the patch that I forgot about. What i really need, it would seem, is some aricept.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

I'm having *precisely* this

helrond - May 22, 2009 - 03:59

I'm having *precisely* this issue, and haven't been able to resolve it. What are the "older dev versions" referenced above, and where can I get them?

 
 

Drupal is a registered trademark of Dries Buytaert.