You are here

function _google_geocode_flatten in Location 7.4

Same name and namespace in other branches
  1. 5.3 geocoding/google.inc \_google_geocode_flatten()
  2. 6.3 geocoding/google.inc \_google_geocode_flatten()
  3. 7.5 geocoding/google.inc \_google_geocode_flatten()
  4. 7.3 geocoding/google.inc \_google_geocode_flatten()
1 call to _google_geocode_flatten()
google_geocode_location in geocoding/google.inc
Perform a geocode on a location array.

File

geocoding/google.inc, line 205
Google geocoder.

Code

function _google_geocode_flatten($location = array()) {

  // Check if its a valid address
  if (empty($location)) {
    return '';
  }
  $address = '';
  if (!empty($location['street'])) {
    $address .= $location['street'];
  }
  if (!empty($location['city'])) {
    if (!empty($address)) {
      $address .= ', ';
    }
    $address .= $location['city'];
  }
  if (!empty($location['province'])) {
    if (!empty($address)) {
      $address .= ', ';
    }

    // @@@ Fix this!
    if (substr($location['province'], 0, 3) == $location['country'] . '-') {
      $address .= substr($location['province'], 3);
      watchdog('Location', 'BUG: Country found in province attribute.');
    }
    else {
      $address .= $location['province'];
    }
  }
  if (!empty($location['postal_code'])) {
    if (!empty($address)) {
      $address .= ' ';
    }
    $address .= $location['postal_code'];
  }
  if (!empty($location['country'])) {
    if (!empty($address)) {
      $address .= ', ';
    }
    $address .= $location['country'];
  }
  return $address;
}