README.txt 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. getdirections module for Drupal 7.x
  2. If you have any questions or suggestions please contact me at
  3. http://drupal.org/user/52366 or use the Getdirections issue queue.
  4. This module provides a form to make a Google directions map.
  5. Installation
  6. Upload the whole getdirections directory into sites/all/modules/ or
  7. sites/<domain>/modules/ for multisite setups.
  8. Login to Drupal site as a user with administrative rights and go to
  9. Administer > Site building > Modules. Scroll down to Other modules section, you
  10. should now see Getdirections module listed there. Tick it and save configuration.
  11. After installation go to Administer > Site configuration > Get directions and
  12. select your preferences and Save Configuration.
  13. If you have the gmap module installed and configured, getdirections will
  14. use its configuration as a starting point.
  15. Also remember to go to Administer > User management > Permissions and
  16. set up permissions according to your needs.
  17. If you have the location or getlocations_fields module installed you can
  18. make use of any nodes containing location information.
  19. For instance, if you want to "preload" the getdirections form with information
  20. about the destination use a URL in this format:
  21. getdirections/location/to/99
  22. Where '99' is the node id (nid) of the location.
  23. The user will only have to fill in the starting point.
  24. To do it the other way around use
  25. getdirections/location/from/99
  26. You can also get a map with waypoints
  27. getdirections/locations_via/1,2,3,99
  28. If you have both the starting point and destination node ids then you can use
  29. getdirections/locations/1/99
  30. Where '1' is the starting point node id and 99 is the destination node id
  31. (note the 's' in locations)
  32. If you are using the location_user or getlocations_fields module you can
  33. make a link to a user's location with the user id:
  34. getdirections/location_user/to/66
  35. Same goes for 'from'
  36. You can also get a map with waypoints of user locations with the user ids:
  37. getdirections/locations_user_via/1,2,3,99
  38. You can mix nodes and users with
  39. getdirections/location_u2n/66/99
  40. Where 66 is is user id, 99 is node id
  41. and vice-versa
  42. getdirections/location_n2u/99/66
  43. Where 66 is is user id, 99 is node id
  44. You can build a map by supplying latitude/longitude pairs delimited with a '|'
  45. eg getdirections/latlons/nn,nn|nn,nn|nn,nn
  46. where nn,nn is a latitude/longitude pair.
  47. A maximum of 8 pairs is permitted by Google unless you have a commercial license.
  48. If you have the Colorbox module installed and enabled in Get Directions
  49. you can place any of the above paths in a colorbox iframe by replacing
  50. 'getdirections' with 'getdirections_box'.
  51. To enable this for a link you can use the 'colorbox-load' method,
  52. make sure that this feature has been enabled in colorbox
  53. and use a url like this:
  54. <a href="/getdirections_box?width=700&height=600&iframe=true" class="colorbox-load">See map</a>
  55. or (advanced use) by adding rel="getdirectionsbox" to the url, eg
  56. <a href="/getdirections_box" rel="getdirectionsbox">See map</a>
  57. The last method uses the settings in admin/settings/getdirections for colorbox
  58. and uses its own colorbox event handler, see getdirections.js. You can define your own
  59. event handlers in your theme's javascript.
  60. 'getdirections_box' has it's own template, getdirections_box.tpl.php which can be
  61. copied over to your theme's folder and tweaked there.
  62. If you install
  63. http://drupal.org/project/menu_attributes
  64. you can get colorbox links into the menu system.
  65. for instance, you can put
  66. getdirections_box?width=700&height=600&iframe=true
  67. in the path and
  68. colorbox-load
  69. in the class textfield
  70. or if you have colorbox enabled in Get Directions:
  71. getdirections_box
  72. in the path and
  73. getdirectionsbox
  74. in the Relationship textfield.
  75. ------------------
  76. Get Directions API
  77. These functions are for use in other modules.
  78. There are functions available to generate these paths:
  79. getdirections_location_path($direction, $nid)
  80. Where $direction is either 'to' or 'from' and $nid is the node id concerned.
  81. getdirections_locations_path($fromnid, $tonid)
  82. Where $fromnid is the starting point and $tonid is the destination
  83. getdirections_locations_via_path($nids)
  84. Where $nids is a comma delimited list, eg "1,2,3,99" of node ids
  85. Google imposes a limit of 25 points
  86. If you have the latitude and longitude of the start and end points you can use
  87. getdirections_locations_bylatlon($fromlocs, $fromlatlon, $tolocs, $tolatlon)
  88. Where $fromlocs is a description of the starting point,
  89. $fromlatlon is the latitude,longitude of the starting point
  90. and $tolocs and $tolatlon are the same thing for the endpoint
  91. See getdirections.api.inc for more detail.
  92. If you are using Views and Location it will provide a 'Get driving directions' block
  93. when you are viewing a location node or a user with a location.
  94. Getdirections now supports the Googlemaps API version 3, this has many new features.
  95. The getdirections_latlon() function can be used in code or called by URL.
  96. getdirections_latlon($direction, $latlon, $locs)
  97. Where $direction is either 'to' or 'from', $latlon is the latitude,longitude to be used
  98. and $locs is an optional string to describe the point being used.
  99. The URL method would be in the form of
  100. <a href="/getdirections/latlon/(from or to)/(lat,lon)/optional description">My Link</a>
  101. You can also use the function getdirections_location_latlon_path() in getdirections.api.inc to
  102. generate the string for you.
  103. Themeing
  104. To change the way the map is displayed you should copy the theme function you want to change
  105. to your theme's template.php, renaming appropriately and editing it there.
  106. There is plenty of help on themeing on drupal.org
  107. An example of a theming change, from http://drupal.org/node/1113042
  108. Your theme should have a template.php,
  109. copy the function theme_getdirections_show() from getdirections.module to your template.php,
  110. renaming it appropriately, eg from
  111. theme_getdirections_show
  112. to
  113. mythemename_getdirections_show
  114. where 'mythemename' is the name of your theme. Then change the following:
  115. $rows[] = array(
  116. array(
  117. 'data' => '<div id="getdirections_map_canvas_' . $mapid . '" style="width: ' . $width . '; height: ' . $height . '" ></div>',
  118. 'valign' => 'top',
  119. 'align' => 'center',
  120. 'class' => array('getdirections-map'),
  121. ),
  122. array(
  123. 'data' => ($getdirections_defaults['use_advanced'] && $getdirections_defaults['advanced_alternate'] ? '<button id="getdirections-undo-' . $mapid . '">' . t('Undo') . '</button>' : '') . '<div id="getdirections_directions_' . $mapid . '"></div>',
  124. 'valign' => 'top' ,
  125. 'align' => 'left',
  126. 'class' => array('getdirections-list'),
  127. ),
  128. );
  129. to
  130. $rows[] = array(
  131. array(
  132. 'data' => '<div id="getdirections_map_canvas_' . $mapid . '" style="width: ' . $width . '; height: ' . $height . '" ></div>',
  133. 'valign' => 'top',
  134. 'align' => 'center',
  135. 'class' => array('getdirections-map'),
  136. ),
  137. );
  138. $rows[] = array(
  139. array(
  140. 'data' => ($getdirections_defaults['use_advanced'] && $getdirections_defaults['advanced_alternate'] ? '<button id="getdirections-undo-' . $mapid . '">' . t('Undo') . '</button>' : '') . '<div id="getdirections_directions_' . $mapid . '"></div>',
  141. 'valign' => 'top' ,
  142. 'align' => 'left',
  143. 'class' => array('getdirections-list'),
  144. ),
  145. );
  146. What this does is rearrange the table so that it produces two rows with one datacell each instead of one row with two datacells.
  147. Make sure you flush the theme registry when you have made the changes, the devel and admin_menu modules are helpful for this.
  148. Putting Getdirections map and list into divs. This example should work with responsive themes.
  149. replace everything from
  150. $header = array();
  151. to
  152. $output .= '<div class="getdirections">' . theme('table', array('header' => $header, 'rows' => $rows)) . '</div>';
  153. with
  154. $output .= '<div class="getdirections">';
  155. $output .= '<div class="getdirections-map" style="width: ' . $width . '; height: ' . $height . '" >';
  156. $output .= '<div id="getdirections_map_canvas_' . $mapid . '" style="width: 100%; height: 100%" ></div>';
  157. $output .= '</div>';
  158. $output .= '<div class="getdirections-list">';
  159. if ($getdirections_defaults['use_advanced'] && $getdirections_defaults['advanced_alternate']) {
  160. $output .= '<button id="getdirections-undo-' . $mapid . '">' . t('Undo') . '</button>';
  161. }
  162. $output .= '<div id="getdirections_directions_' . $mapid . '"></div>';
  163. $output .= '</div>';
  164. $output .= '</div>';
  165. Blocks.
  166. Here is a simple way to crete a block with a form and map in it. Ensure you have php filter enabled and add
  167. <?php
  168. if (arg(0) == 'node') {
  169. $nid = arg(1);
  170. if (is_numeric($nid) && $nid > 0) {
  171. echo getdirections_setlocation('to', $nid);
  172. }
  173. }
  174. ?>
  175. This will only show on node view.
  176. see http://drupal.org/node/880332
  177. Adding a map directly into a block:
  178. See http://drupal.org/node/1376392#comment-7135346
  179. Create a custom block. Use the php filter for the content. Then paste this into your block content:
  180. <?php
  181. $n = FALSE;
  182. $nid = FALSE;
  183. if (arg(0)) {
  184. $n = arg(0);
  185. }
  186. if (arg(1)) {
  187. $nid = arg(1);
  188. }
  189. if ($n && $nid && is_numeric($nid) && $nid > 0) {
  190. $l = getdirections_load_locations($nid, $n);
  191. if ($l) {
  192. echo getdirections_entity_setlocation($n ,'to', $nid);
  193. }
  194. }
  195. ?>