function location_feeds_set_point in Location Feeds 6
Same name and namespace in other branches
- 7 location_feeds.module \location_feeds_set_point()
Sets a latitude or longitude point for the node and attempts to recognize either decimal or DMS notation.
Parameters
object $object:
string $target: The target that invoked this
$value:
Return value
$object
1 string reference to 'location_feeds_set_point'
- _location_feeds_fill_targets in ./
location_feeds.module - Helper function to add target fields
File
- ./
location_feeds.module, line 232 - This module provides location mappers to feed importers.
Code
function location_feeds_set_point($object, $target, $value) {
list($field_name, $sub_field) = explode(':', $target);
if (strpos($sub_field, '][') !== FALSE) {
list($sub_field, $last_field) = explode('][', $sub_field, 2);
}
if (!is_array($value)) {
$value = array(
$value,
);
}
foreach ($value as $i => $val) {
$val = trim($val);
if (!is_numeric($val)) {
$neg = FALSE;
if (strpos($val, '-') === 0) {
$neg = TRUE;
}
$val = trim(preg_replace('/[^\\d\\s\\.WSws]/', '', $val));
$dms = explode(' ', $val);
// Account for '77° 02' 15.691" W' format.
if (count($dms) == 4) {
if ($dms[3] == 'W' || $dms[3] == 'w' || $dms[3] == 'S' || $dms[3] == 's') {
$neg = TRUE;
unset($dms[3]);
}
}
$val = (abs($dms[0]) + $dms[1] / 60 + $dms[2] / 3600) * ($neg ? -1 : 1);
}
if (isset($last_field)) {
$object->{$field_name}[$i][$sub_field][$last_field] = $val;
}
else {
$object->{$field_name}[$i][$sub_field] = $val;
}
}
return $object;
}