I read the readme.txt file and have installed and configured the module but I can't work out how to get it to work! I have location and gmap installed. I would like to show a link 'get direction' under the map from the location module. I'm sorry if this is a very straight forward question but can someone please explain how to get started?
Thanks!

Comments

hutch’s picture

Using the Views module is probably the best way to get started, Getdirections will provide you with a View in a Block with a link to point to a Getdirections form and map.
You can't really put a link inside the location display, you would have to hack the Location module or possibly use a hook_form_alter function.
If your theme has an appropriate region that can take a block then you can do it there. The block will only appear when you are looking at the node.

LTech’s picture

Thanks for the start - I would never have thought to look for that block. I've enabled the block but when you click on the links it just takes you to an empty page. with the title "Get directions to .... ".
How do I integrate the location field so I get directions to an address?
I'm finding the readme.txt difficult to get started with. Thanks for your help.

LTech’s picture

It seems to be working fine now... though I don't think I made any changes. Does it take time to cache?
Thanks for getting me started.

LTech’s picture

btw it is a really cool module! Thanks

hutch’s picture

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

Component: Code » Documentation
Status: Closed (works as designed) » Active
Issue tags: +Get Directions module instructions

"Using the Views module is probably the best way to get started, Getdirections will provide you with a View in a Block with a link to point to a Getdirections form and map"

Sorry, I'm a Drupal newb, still can't seem to get started. I don't see a getdirections block anywhere.

Can someone please assist with some spoonfeeding?

Thanks!

hutch’s picture

Go to the administration page for menu Navigation at admin/structure/menu/manage/navigation
Enable "Get Directions"
This will give you a link to the Getdirections map and form.

If you are using either Getlocations Fields or location modules and have created a content type with one of these attached to it and have created some nodes with locations associated with them you can use Views to create a view that will provide a link to a Getdirections map and form with the 'To' already filled in.

Install Views.
Go to the administration page for Views at admin/structure/views
Enable the getdirections view.
Go to the Blocks administration page at admin/structure/block and add the getdirections block to somewhere eg sidebar. The block will appear when you are on the node page.

stevengraff’s picture

Thanks; that was helpful.

When I go to the list of menu links, the link for Get Directions seems to work, i.e. it shows me a fresh page with a map and form on it, but activating and placing the block into a section (i.e. content) doesn't seem to do anything at all -- it does not appear.

hutch’s picture

The content has to have either a Getlocations Fields or a location field enabled and filled in. That is where the 'To' address will come from.

Install Getlocations (read the instructions on the project page), enable the Getlocations Fields module, configure both under Configuration > Web services, create a new content type under Structure > Content types (name it 'With Address' for instance) and add a field 'Getlocations Fields'. Configure that and save.

This will give you a content type with a map and address form. Create some nodes of this type, filling in the address. Google will geocode the address and you will have a latitude and longitude for that address. Once you have that the rest will fall into place.

You could also use the Location module but in my opinion Getlocations is better, but then I wrote it so I would say that ;-)

stevengraff’s picture

Thanks; when I enable the Getlocations module I get:

Error message
Getlocations is unable to save the marker configuration, so the markers will not work. Please check file system permissions of sites/default/files/js/getlocations_markers.js!

Any idea what might cause this?

hutch’s picture

Have you regenerated the marker cache under 'admin/config/services/getlocations'?

If that is what caused the message you need to do what the message says:
check file system permissions of sites/default/files which should be writeable by anyone eg 777.

I am assuming that you have followed the instructions on the Getlocations project page and installed some markers in sites/all/libraries.

stevengraff’s picture

"I am assuming that you have followed the instructions on the Getlocations project page"

You mean the bit that says:

"Important:
Please read and follow the instructions in README.txt. You need to do this to get markers working. You will need at least the first one in the lists below."

Of course not! :) I'll do that today. Thanks again.

stevengraff’s picture

Well, weirdly enough, I can manually set the permissions to 777, but when I try to enable Get Locations, I get the failure message and the permissions revert to 775.

OK; I've gotten the permissions to "stick" at 777, but the file getlocations_markers.js is nowhere to be found.

stevengraff’s picture

I manually created an empty file called getlocations_markers.js and uploaded it into the js directory. Upon updating Drupal, the file got "populated" with script and is now 4kb in size. When I disable/enable getlocations now I get a success message rather than the error message. Thus I am now past this particular impediment.

I rechecked permissions on the js directory, and they are still 777. I would say this problem warrants further investigation aside from the fact that no one else seems to have experienced it, so perhaps it's just related to something else off-kilter in my site configuration or permissions.

gpenn’s picture

Hutch, Thanks for this great module. We Drupal newbies really appreciate it. But there's something I can't figure out (did I mention I'm a newbie?).

1. I installed Getdirections and Location.
2. I created a page and associated it with a location.
3. I linked (in a menu) to that page from my front page.
4. I placed the Getdirections block on that page.

The block links to yet another page that works perfectly (with the destination already chosen and the map and form at the ready). But is there someway to arrive at that perfectly working page directly from my menu link, without going through the middle page? I tried placing the block on my front page, but it didn't even appear. I'm guessing that's because there's no location associated with the front page. How would one associate a location with a front page? Or can one create a Getdirections block that shows the final map and form without having to click through another link?

From my searches, I notice that many solutions to folks' issues involve PHP code. I'm happy to insert some, but because of my newbieness, I'll need to know exactly where it goes.

Thanks in advance for your help.

gpenn’s picture

And, since I'm asking basic questions, how can I pre-fill the "Country" box in the "from" address so that people don't have to select USA each time?

hutch’s picture

The block is designed to show up when you are on a page/node that is location enabled, providing a link to the getdirections map on how to get there. If you want a link to the getdirections map without anything filled in already, create a menu item '/getdirections'
If you want the home page location enable use a content type that is location enabled for the home page.

You might want to try the Getlocations module, it has a submodule Getlocations Fields that is a replacement for the Location module with full support for Google version 3 maps.

As always, read the README.txt files ;-)

To set the default country, go to admin > configuration > Regional and language > Regional settings.

gpenn’s picture

Thanks, Hutch, for the push in the right direction. Unfortunately, advanced developers like you and README files often assume knowledge that the interlocutor/reader simply doesn't have. For instance, the Getdirections README file explains: "if you want to "preload" the getdirections form with information about the destination use a URL in this format: getdirections/location/to/99 where '99' is the node id (nid) of the location." But it doesn't say how to use that URL. It finally dawned on me that I could create a menu item and assign it to that path. I know this seems beyond simple to you, but for those of us out here who love what Drupal can do but haven't any expertise, these small connecting pieces of information help vastly.

So, for others like me who are in charge of a small site (a church, in my case) and need a simple link on the homepage to a getdirections form and map with the "to" box already filled in with the location of your organization/business/church, here are the steps (in Drupal 7):

  1. Upload both the Getdirections and the Location modules, enable them (Getdirections under Other; Location and Node Locations under Location) and fix the permissions.
  2. Take a minute to determine your latitude/longitude. There are plenty of coordinate finders on the web; just google “latitude longitude” and pick one. It’ll ask for your address and will give you the coordinates (you want the decimal version, not the degrees version).
  3. Configure Getdirections. There are lots of choices, but most importantly, you want to put the coordinates into the “Map center” box. (Separate the two numbers with a comma but no spaces.) Save the configuration. You can also configure Location, but the default settings seem to work well.
  4. You’re going to create a new content node. But first go to Structure>Content types and edit the content type you plan to use—a basic page will do. Open the Locative information box (which should appear because you’ve uploaded the Location module). If, like me, you are only creating one location node for your organization, you can enter your address in the Default boxes and, under Collect, pick Force Default for everything. For Coordinate Chooser, pick Allow. If you want more flexibility, leave it all blank and choose Allow for everything. Save the content type.
  5. Now create a new content node of the type you just saved (e.g., a page). Give it a title like “My Location” and don’t worry about body text (nobody will actually see this page).
  6. At the bottom of the screen, you can skip most of the stuff, like menu settings, URL path settings, etc. But open the “Location” box. If you filled in all the default boxes, that info should already be there. You can also enter the coordinates you found earlier. Save the node.
  7. Make a note of the node number, which you’ll find in the address line when you’re viewing the page (e.g., node/88).
  8. Go to Structure>Menus, choose the menu you want the link to appear in (whatever menu appears on your homepage), open the list of links, and click on “Add Link”.
  9. Give the menu link a title, e.g., “Directions”, and in the Path box, enter “getdirections/location/to/88” (or whatever the number is of the node you created). Make sure the menu link is enabled, and save.

You’re done! Go to your homepage, find the new menu link, click on it, and—if all goes well—you should be brought to a page that has the Getdirections form with the “to” information already there and a map with your place smack-dab in the center.

Try it. Type in a Starting from address, submit, and you’ll see how wonderful Hutch’s module is.

PS: I still get the “from” country box without my site’s default (USA) showing, but it seems that the system knows what the default is. So I used a bit of CSS magic to make that box disappear.

hutch’s picture

The Location module has it's own default country setting and Getdirections uses that when you are using the Location module.

gpenn’s picture

Thanks. I had already set the Location module default country to US, and I believe the logic recognizes that, but I still get "Please select" in the Country box. But no matter, as I've hidden that box from view.

I do have another question, though: is there some way to set the traffic and bicycling info toggle switches to off in their first state. As it is now, the map opens and automatically loads the traffic/bike info, and the user has to toggle them off. I'd prefer that the map load clean, and the user would have to toggle the information on. Possible?

Thanks.

hutch’s picture

There is no facility for setting this is admin/config/getdirections, but you could do it in whatever javascript file you are using (look in the html source to see which one).
I might add this to the code at some time, I'm rather busy at the moment.

hutch’s picture

The latest dev has an "Activate" option for all the buttons, traffic, transit, bicycle, panoramio, weather and cloud, so now you can have the button enabled but not applied to the map on initial view.
Available with git or later tonight.
EDIT: oops this only applies to the Getlocations module as yet, sorry about that.

dharam1987’s picture

Title: how to get started? » How to make the block to use the map directly (not a new page)

No doubt, it is a great module, but I have got a requirement and is wondering how make use of getdirections as a block in my page, which is a view that is displaying the map using gmap module, I would like the block to show the form and upon clicking get directions, it shouldn't redirect the user to a new page, it should stay on the same and and display the directions.

What I have done.

1- I have gmap module and location module aswell

2- I have a content type where I am adding the locations, latitude and longitude

3- Now, I have created a view to display the map, My view is using the format (GMAP). The map is coming perfectly.

4- Now, I want to have get directions form in this page, and even if the page refresh happens, it should always display this page and use this map.

http://goo.gl/r4Or7 is the URL where the view is display google map using GMAP (format).

I am sure this setting might be there somewhere, but I am not getting it. After doing more-experiments, I would love to create a documentation with use-cases of get-directions module.

hutch’s picture

This will not be simple, but is probably doable.
First, getting the form into your page. To do that you will probably need some PHP in your page which will fetch, render and theme the form. See the bottom of function getdirections_direction() for some hints. You can import the theme 'getdirections_show' into your theme's template.php and edit that to prevent a map div from being created.
You will need to ensure that the Getdirections settings are being loaded into CDATA. function getdirections_direction() will show you how.
You will need to use your own version of getdirections_v2.js or getdirections_v2a.js, you can set this in admin > config > getdirections at the bottom of the form.
Your version will need to be told which map is being used, prevent the default map from being created but still ensure that the other actions work on your map. I don't know wether Gmap makes the map object globally available so that you can act on it.

jamesbenison’s picture

Create a custom block. Use the php filter for the content. Then paste this into your block content:

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

I think that will do what you're looking for.

Edit: You will need to have the php filter module enabled.

lias’s picture

Thanks for the code. This worked for Geofield and Addressfield.

hutch’s picture

I will be adding #25 to the README.txt, nice clean and simple, no Views overhead.

peacog’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev

Thank you for the excellent module. I've been trying out version 3.x and see that the getdirections_setlocation() function is no longer available. What's the correct way to put the map in a block in 3.x?

hutch’s picture

Try something like

$map = getdirections_entity_setlocation('node', 'to', $nid);

This assumes your target is a node.

screeno’s picture

After adding the block as described in #25 above, I get a WSOD when I go to a page that uses the script. The log shows the following:

Notice: Undefined variable: nid in eval() (line 2 of /Applications/MAMP/htdocs//modules/php/php.module(80) : eval()'d code).

Any idea why this is happening?

Here's an update to this post. I swapped out the code with the following as per the readme:

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

I am still getting a white screen but am no longer getting any log message related to the script. I know the code in the block is capturing the nid because I modified the code to print out the nid and it shows the correct nid.

hutch’s picture

The function getdirections_setlocation() does not exist in 7.x-3.x, my bad, I did not update the README when I created the 3.x series.

$n = arg(0);
if ($n == 'node') {
  $nid = arg(1);
  $l = getdirections_load_locations($nid, $n);
  if ($l && is_numeric ($nid) && $nid > 0) {
    echo getdirections_entity_setlocation($n, 'to', $nid);
  }
}

This also checks if the node is location enabled.

screeno’s picture

Fantastic! This worked beautifully. One other small item. When the page first loads and the from field has not been filled in the form, an empty table is displayed below the from field. How do I hide that table until the form is processed?

Thanks for this very helpful module.

hutch’s picture

Hmm, I don't see a table, are you seeing the map with the "to" location marked with a marker?

joco_sp’s picture

#31 worked.

Is there a way to have both fields filled with values from the field 'to' and 'from'? and get the route automaticly from one location to another?

hutch’s picture

Have a look at function getdirections_entity_setlocations()