You are here

private function geofield_handler_argument_proximity::parseAddress in Geofield 7.2

Interpret URL args as an address with optional distance attached.

Return latitude, longitude and distance as an array.

Parameters

array of arguments, e.g. result of arg():

Return value

array(lat, lon, dist) or FALSE if arguments could not be parsed.

1 call to geofield_handler_argument_proximity::parseAddress()
geofield_handler_argument_proximity::parseArg in views/handlers/geofield_handler_argument_proximity.inc

File

views/handlers/geofield_handler_argument_proximity.inc, line 177
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

private function parseAddress($args) {
  if (empty($args)) {
    return FALSE;
  }

  // Interpret the last arg as a distance, if it is numeric.
  $dist = is_numeric(end($args)) ? array_pop($args) : $this
    ->getDefaultDist();
  $address = implode(', ', $args);
  if (!empty($address) && module_exists('geocoder')) {
    $all_geocoder_engines = array_keys(geocoder_handler_info('text'));

    // Pick Google if defined, otherwise the first in the list.
    $geocoder_engine = in_array('google', $all_geocoder_engines) ? 'google' : reset($all_geocoder_engines);
    if ($geocoded_data = geocoder($geocoder_engine, $address)) {
      return array(
        'latitude' => $geocoded_data
          ->getY(),
        'longitude' => $geocoded_data
          ->getX(),
        'distance' => $dist,
      );
    }
  }
  return FALSE;
}