function geofield_handler_argument_proximity::parseLatLonDistArg in Geofield 7.2
Extract lat,lon and distance from arg and return as array.
Parameters
type $arg_string:
Return value
array(lat, lon, dist) or FALSE if string could not be parsed.
1 call to geofield_handler_argument_proximity::parseLatLonDistArg()
File
- views/
handlers/ geofield_handler_argument_proximity.inc, line 122 - Geofield contextual filter argument handler for Views.
Class
- geofield_handler_argument_proximity
- The proximity argument may be appended to URL in the following format: /lat,lon_dist where dist is a positive number representing a circular proximity in either kilometers or miles, as configured through the contextual filter UI.
Code
function parseLatLonDistArg($arg_string) {
$args = array_filter(preg_split(GEOFIELD_PROXIMITY_REGEXP_PATTERN, $arg_string));
foreach ($args as $value) {
if (!is_numeric($value)) {
return FALSE;
}
}
if (count($args) == 3) {
// Got lat + lon + dist: we're good to go
// Use next() on $args as after array_filter() we cannot be sure what
// the element indices are.
return array(
'latitude' => reset($args),
'longitude' => next($args),
'distance' => next($args),
);
}
// Either distance or lat,lon where omitted. See if we can get these
// from the defaults.
$lat = reset($args);
$lon = next($args);
if ($lat !== FALSE && $lon !== FALSE) {
// 2 args received, interpret as lat,lon and take distrance from default
if ($dist = $this
->getDefaultDist()) {
return array(
'latitude' => $lat,
'longitude' => $lon,
'distance' => $dist,
);
}
return FALSE;
}
if ($lat !== FALSE && $lon === FALSE) {
// 1 arg received, interpret as distance and take lat,lon from default
$dist = $lat;
$defaults = $this
->getDefaultLatLonDist();
if (count($defaults) < 2) {
return FALSE;
}
return array(
'latitude' => reset($defaults),
'longitude' => next($defaults),
'distance' => $dist,
);
}
// If we get here, we're dealing with rubbish
return FALSE;
}