You are here

function location_map_link in Location 7.5

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

Get a deep-link to a mapping service such as Yahoo! Maps or MapPoint given an location. The call is delegated based on the 'country' value in the $location parameter.

Parameters

$location: An associative array where 'street' => A string representing the street location 'additional' => A string for any additional portion of the street location 'city' => A string for the city name 'province' => The standard postal abbreviation for the province 'country' => The two-letter ISO code for the country of the location (REQUIRED) 'postal_code' => The international postal code for the location

Return value

A link to a map provided by a third-party. The idea is to encode the appropriate parameters as HTTP GET variables to the URL.

Related topics

1 call to location_map_link()
template_preprocess_location in ./location.module
Theme preprocess function for a location.

File

./location.inc, line 38

Code

function location_map_link($location = array(), $link_text = 'See map: ') {
  if (!isset($location['country']) || $location['country'] == 'xx') {
    return '';
  }
  location_load_country($location['country']);
  $default_func = 'location_map_link_' . $location['country'] . '_default_providers';
  $providers_func = 'location_map_link_' . $location['country'] . '_providers';
  $providers = function_exists($providers_func) ? $providers_func() : array();
  $selected_providers = variable_get('location_map_link_' . $location['country'], function_exists($default_func) ? $default_func() : array());
  $links = array();
  foreach ($selected_providers as $mapper) {
    $link_func = 'location_map_link_' . $location['country'] . '_' . $mapper;
    if (function_exists($link_func)) {
      if ($link = $link_func($location)) {
        $links[] = '<a href="' . $link . '"' . (variable_get('location_maplink_external', 0) ? ' ' . variable_get('location_maplink_external_method', 'target="_blank"') : '') . '>' . $providers[$mapper]['name'] . '</a>';
      }
    }
  }
  if (count($links)) {
    return '<div class="location map-link">' . t($link_text) . implode($links, ", ") . '</div>';
  }
  else {
    return NULL;
  }
}