You are here

function location_address2singleline in Location 7.5

Same name and namespace in other branches
  1. 5.3 location.inc \location_address2singleline()
  2. 5 location.inc \location_address2singleline()
  3. 6.3 location.inc \location_address2singleline()
  4. 7.3 location.inc \location_address2singleline()
  5. 7.4 location.inc \location_address2singleline()

Create a single line address.

Parameters

$location: Array. The address parts

Return value

String. The single line address

3 calls to location_address2singleline()
location_geocode_au_yahoo in supported/location.au.inc
location_geocode_ca_geocoder in supported/location.ca.inc
This needs some more work to cover errors and such. I think showing a proper Drupal error is a good idea. If an incorrect address is given to geocoder.ca it offers a suggestion. If this happens the drupal user should be told.
location_geocode_us_yahoo in supported/location.us.inc

File

./location.inc, line 595

Code

function location_address2singleline($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($location['street'])) {
      $address .= ', ';
    }
    $address .= $location['city'];
  }
  if (!empty($location['province'])) {
    if (!empty($location['street']) || !empty($location['city'])) {
      $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'])) {
    $address .= ', ' . $location['country'];
  }
  return $address;
}