You are here

function getdirections_setlocations in Get Directions 6.2

Same name and namespace in other branches
  1. 6 getdirections.module \getdirections_setlocations()
  2. 7.2 getdirections.module \getdirections_setlocations()

Function to setup the map

Parameters

int $fromnid: Required. The nid of the starting point

int $tonid: Required. The nid of the destination

Return value

Returns the themed map

1 call to getdirections_setlocations()
getdirections_direction_box in ./getdirections.module
1 string reference to 'getdirections_setlocations'
getdirections_menu in ./getdirections.module
Implementation of hook_menu().

File

./getdirections.module, line 878
Fetches google map directions.

Code

function getdirections_setlocations($fromnid, $tonid, $width = '', $height = '') {
  if (module_exists('location')) {

    // From
    $fromvid = getdirections_get_vid($fromnid);
    $fromlocation = location_load_locations($fromvid);
    if (count($fromlocation)) {
      $fromlatlon = $fromlocation[0]['latitude'] . ',' . $fromlocation[0]['longitude'];

      // sanity check
      if (!getdirections_latlon_check($fromlatlon)) {
        watchdog('getdirections', 'Lat, Lon failed for node id !nid', array(
          '!nid' => $fromnid,
        ), WATCHDOG_WARNING);
        $fromlatlon = getdirections_load_latlon_defaults();
      }
      $fromlocs = _getdirections_loadaddress($fromlocation[0]);

      // To
      $tovid = getdirections_get_vid($tonid);
      $tolocation = location_load_locations($tovid);
      if (count($tolocation)) {
        $tolatlon = $tolocation[0]['latitude'] . ',' . $tolocation[0]['longitude'];

        // sanity check
        if (!getdirections_latlon_check($tolatlon)) {
          watchdog('getdirections', 'Lat, Lon failed for node id !nid', array(
            '!nid' => $tonid,
          ), WATCHDOG_WARNING);
          $tolatlon = getdirections_load_latlon_defaults();
        }
        $tolocs = _getdirections_loadaddress($tolocation[0]);
        $content = getdirections_locations($fromlocs, $fromlatlon, $tolocs, $tolatlon, $width, $height);
        return $content;
      }
    }
  }
  return getdirections_direction();
}