function ip_geoloc_get_location_from_term in IP Geolocation Views & Maps 7
Returns the location object belonging to supplied region taxonomy term id.
Parameters
int $tid: Taxonomy term identifier
int $return_parent: To return location of the parent (1) or grand-parent (2) rather than the supplied region term.
Return value
array, location info
1 call to ip_geoloc_get_location_from_term()
File
- ./
ip_geoloc_blocks.inc, line 808 - Blocks available in IP Geolocation Views & Maps.
Code
function ip_geoloc_get_location_from_term($tid, $parent = 0) {
$parents = taxonomy_get_parents_all($tid);
if (empty($parents)) {
return array(
'provider' => 'taxonomy',
'ip_address' => ip_address(),
);
}
$term = $parents[min($parent, count($parents) - 1)];
// Get lat,lng from the Geofield on this term
$geo_vocabulary_id = variable_get('ip_geoloc_geo_vocabulary_id', 0);
$vocabulary = taxonomy_vocabulary_load($geo_vocabulary_id);
foreach (field_info_instances('taxonomy_term', $vocabulary->machine_name) as $field_name => $field_instance) {
$field = field_info_field($field_name);
if ($field['type'] == 'geofield') {
$value = reset($term->{$field_name});
$value = is_array($value) ? reset($value) : array();
if (empty($value['lat'])) {
drupal_set_message(t('The latitude and longitude of the term %name are not known.', array(
'%name' => $field_name,
)), 'warning');
$value = array(
'lat' => NULL,
'lon' => NULL,
);
}
return array(
'provider' => 'taxonomy',
'is_updated' => TRUE,
'ip_address' => ip_address(),
'region' => $term->tid,
'latitude' => $value['lat'],
'longitude' => $value['lon'],
);
}
}
}