You are here

function location_handler_argument_location_proximity::calculate_coords in Location 7.5

Same name and namespace in other branches
  1. 6.3 handlers/location_handler_argument_location_proximity.inc \location_handler_argument_location_proximity::calculate_coords()
  2. 7.3 handlers/location_handler_argument_location_proximity.inc \location_handler_argument_location_proximity::calculate_coords()
  3. 7.4 handlers/location_handler_argument_location_proximity.inc \location_handler_argument_location_proximity::calculate_coords()
1 call to location_handler_argument_location_proximity::calculate_coords()
location_handler_argument_location_proximity::query in handlers/location_handler_argument_location_proximity.inc
Set up the query for this argument.

File

handlers/location_handler_argument_location_proximity.inc, line 64
Location proximity argument handler.

Class

location_handler_argument_location_proximity
Argument handler to accept proximity

Code

function calculate_coords() {
  if (!empty($this->value['latitude']) && !empty($this->value['longitude'])) {

    // If there are already coordinates, there's no work for us.
    return TRUE;
  }

  // @@@ Switch to mock location object and rely on location more?
  if ($this->options['type'] == 'postal') {
    if (!isset($this->value['country'])) {
      $this->value['country'] = variable_get('location_default_country', 'us');
    }

    // Zip code lookup.
    if (!empty($this->value['postal_code']) && !empty($this->value['country'])) {
      location_load_country($this->value['country']);
      $coord = location_get_postalcode_data($this->value);
      if ($coord) {
        $this->value['latitude'] = $coord['lat'];
        $this->value['longitude'] = $coord['lon'];
      }
      else {
        $coord = location_latlon_rough($this->value);
        if ($coord) {
          $this->value['latitude'] = $coord['lat'];
          $this->value['longitude'] = $coord['lon'];
        }
        else {
          return FALSE;
        }
      }
    }
    else {
      return FALSE;
    }
  }
  return TRUE;
}