I was wondering if it might be possible to have a Get Directions block. I don't mean a link to a get directions page. I mean A block with all the functionality present on a get directions page - form and map, present in a block, that could be added to pages that have a location cck field.

Comments

aufumy’s picture

you could do what I mentioned in this issue:
http://drupal.org/node/880234

Add php code to a page/block

echo getdirections_direction();
michaelscappa’s picture

hutch, i wouldn't mind helping out with this module if its ok with you. I can work on this...

hutch’s picture

I'm willing to consider any patches anyone wants to submit ;-)

hutch’s picture

While on the subject of adding features, if anyone would like to consider adding something like the stuff in http://econym.org.uk/gmap/example_multi2.htm that would be very useful.

Broda’s picture

I've created a get directions block using getdirections_locations_bylatlon() function and it works great. A problem comes up when there are multiple blocks on the same page - none of the maps/directions show up. I believe it's a problem with the map divs having the same ID. What's the best way to fix this? A function override? If so, which function?

hutch’s picture

Hmmm, difficult, I can't think of a mechanism for telling one instance about another and the ids, getdirections_map_canvas and getdirections_directions are hardwired into the javascript and in the theme functions. Furthermore the javascript is designed to run for one map and right now I can't think how it could be written to do otherwise. Iframes might work but I'm not sure how to avoid hauling in headers, menus etc. There is a module for managing Iframes but I have no experience of it as yet.
If the routes you want to display are fixed you could cheat by screengrabbing the map and displaying that in the block, linking it to the full page for that route.

hutch’s picture

Replying to my own posting here, the features found at http://econym.org.uk/gmap/example_multi2.htm are now in dev, tested in firefox and chrome so far.

hutch’s picture

Status: Active » Closed (works as designed)
jfrazier’s picture

<?php
echo getdirections_direction();
?>

This code does the job of adding the get directions widget to a block that I can add to the sidebar of my location node. But it leaves the 'from' and 'to' fields blank respectively. The only thing I need is to figure out how to pre-populate the destination (and make it work), but I can't figure it out.

I've tried:

<?php
echo getdirections_direction('to', $nid);
?>
<?php
echo getdirections_direction('to', $lid);
?>
<?php
echo getdirections_direction('to', nid);
?>
<?php
echo getdirections_direction('to', lid);
?>

I've been reading the getdirections.api.inc and forums for hours banging my head against this wall. I've tried Views to create a block, etc. Obviously I'm out of my element on this one. Any help appreciated.

jfrazier’s picture

Hutch, is this is even possible? Thank you very much.

jfrazier’s picture

Broda, does your solution work for any node location, or only if you supply the Lat / Long in your function?

hutch’s picture

try something like this:

$nid = 3;
echo getdirections_setlocation('to', $nid);

or a bit fancier:

$n = arg(0);
if ($n == 'node') {
$nid = arg(1);
$map = getdirections_setlocation('to', $nid);
echo $map;
}

This last one will only show wherever the first item in the path is 'node'

jfrazier’s picture

Thank you!!! Thank you!!! Yeah!!

The second option works best for me, since the get directions block is on multiple location node pages. So it will set the destination based on what page it's on. Wonderful module and support!

jfrazier’s picture

Weird side effect though, the page title is now reflected as "Get directions to (node title)" i.e. "Get directions to Christie Dental of Belleview" where the title of the node is Christie Dental of Belleview. How could this code override the page title? Any idea how to resolve it?

Nevermind -- found it. Line 272 of getdirections.module in case anyone else is looking.

hutch’s picture

This version would be a bit more robust as it would only open on a node view

if (arg(0) == 'node') {
  $nid = arg(1);
  if (is_numeric($nid) && $nid > 0) {
    echo getdirections_setlocation('to', $nid);
  }
}
bmateus’s picture

Regarding comment #14, on version 6.x-2.8, it's line 244 of getdirections.module.

if ($type == 'node') {
      $node = node_load(array('nid' => $id ));
      drupal_set_title(t('Get directions @d @t', array('@d' => $direction_translated, '@t' => $node->title)));
    }
jusyjim’s picture

Does this still work for Drupal 7 nodes with geofields? Is there an adjustment? I'm getting fatal error.

hutch’s picture

If you look up node_load() for Drupal 7 on api.drupal.org you will see that it now only needs the $id, so $node = node_load($id);

jusyjim’s picture

Thanks!! Happy New Year!!

jusyjim’s picture

I tried to apply your code but after sitting down and looking at it I'm confused. I wasn't specific about which post I was referring to. I was referring to the block code in comment #15. It looks like the code you posted is for comment 16. Sorry for the confusion.

This is the code that is giving me the error:

<?php
if (arg(0) == 'node') {
  $nid = arg(1);
  if (is_numeric($nid) && $nid > 0) {
    echo getdirections_setlocation('to', $nid);
  }
}
?>
hutch’s picture

If you try the version given in the README.txt at the bottom of the file you will have more luck. I am assuming you are using 7.x-3.x but you have supplied almost no imformation at all, it's hard to help you when you are not helping me.

hutch’s picture

The function getdirections_setlocation() has been restored in 7.x-3.x current dev to provide backwards compatibility