function location_map_link in Location 7.3
Same name and namespace in other branches
- 5.3 location.inc \location_map_link()
- 5 location.inc \location_map_link()
- 6.3 location.inc \location_map_link()
- 7.5 location.inc \location_map_link()
- 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
array $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
string $link_text: Text for a link.
Return value
string 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 43 - Public API for the Location module.
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';
// Merge the global providers with country specific ones so that countries
// can add to or override the defaults.
$providers = function_exists($providers_func) ? array_merge(location_map_link_providers(), $providers_func()) : location_map_link_providers();
// Default providers will be taken from the country specific default providers
// function if it exists, otherwise it will use the global function.
$selected_providers = variable_get('location_map_link_' . $location['country'], function_exists($default_func) ? $default_func() : location_map_link_default_providers());
$links = array();
foreach ($selected_providers as $mapper) {
$link_func = 'location_map_link_' . $location['country'] . '_' . $mapper;
// If there is no country function try for a global one.
$link_func = function_exists($link_func) ? $link_func : 'location_map_link_' . $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;
}
}