You are here

function location_driving_directions_link in Location 7.5

Same name and namespace in other branches
  1. 5.3 location.inc \location_driving_directions_link()
  2. 5 location.inc \location_driving_directions_link()
  3. 6.3 location.inc \location_driving_directions_link()
  4. 7.3 location.inc \location_driving_directions_link()
  5. 7.4 location.inc \location_driving_directions_link()

Takes two locations and tries to return a deep-link to driving directions.

Parameters:

Parameters

$location_a: An associative array that represents an location where 'street' => the street portions of the location 'additional' => additional street portion of the location 'city' => the city name 'province' => the province, state, or territory 'country' => lower-cased two-letter ISO code (REQUIRED) 'postal_code' => the postal code

$location_b: An associative array that represents an location in the same way that parameter $location_a does.

$link_text: The text of the HTML link that is to be generated.

Return value

A deep-link to driving directions on Yahoo! or some other mapping service, if enough fields are filled in the parameters. A deep-link to a form for driving directions with information pre-filled if not enough, but some fields are filled in the parameters. The empty string if no information is provided (or if so little information is provided that there is no function to which to delegate the call.

We dispatch the call to a country-specific function. The country-specific function, in this case, will be the one reflected by the country parameter of the first function. We require that both locationes supplied have a country field at the minimum.

The country-specific functions will ultimately decide, with the parameters given, whether to to link to a form for driving directions is provided, where this form will be pre-populated with whatever values were available or whether to link directly to the driving directions themselves if enough fields are filled for each location.

Related topics

File

./location.inc, line 184

Code

function location_driving_directions_link($location_a = array(), $location_b = array(), $link_text = 'Get directions') {
  if (!isset($location_a['country']) or !isset($location_b['country'])) {
    return '';
  }

  // For now, return empty string if starting-point and destinations are in different countries

  //if ($location_a['country'] != $location_b['country']) {

  //  return '';

  //}

  // Lines above commented out because I want to let the country-specific function of the departure point decide
  // what it will do with driving destination locationes from other countries.  As an example, Yahoo! Maps supports driving
  // direction queries for locations between the U.S. and Canada.
  $driving_direction_function = 'location_driving_directions_link_' . $location_a['country'];
  if (function_exists($driving_direction_function)) {
    $http_link = $driving_direction_function($location_a, $location_b);
    if (strlen($http_link)) {
      return '<a href="' . $http_link . '">' . $link_text . '</a>';
    }
    else {
      return '';
    }
  }
  return '';
}