You are here

function location_latlon_rough_au in Location 7.4

Same name and namespace in other branches
  1. 5.3 supported/location.au.inc \location_latlon_rough_au()
  2. 6.3 supported/location.au.inc \location_latlon_rough_au()
  3. 7.5 supported/location.au.inc \location_latlon_rough_au()
  4. 7.3 supported/location.au.inc \location_latlon_rough_au()

Returns a lat/lon pair of the approximate center of the given postal code in the given country

Parameters

$location: An associative array $location where 'street' => the street portion of the location 'supplemental' => additional street portion of the location 'province' => the province, state, or territory 'country' => lower-cased two-letter ISO code (REQUIRED) 'postal_code' => the international postal code for this location (REQUIRED)

Return value

An associative array where 'lat' => approximate latitude of the center of the postal code's area 'lon' => approximate longitude of the center of the postal code's area

File

supported/location.au.inc, line 22

Code

function location_latlon_rough_au($location = array()) {
  if (!isset($location['postal_code'])) {
    return NULL;
  }
  $result = db_query("SELECT latitude, longitude FROM {zipcodes} WHERE country = :country AND zip = :zip", array(
    ':country' => $location['country'],
    ':zip' => substr(str_pad($location['postal_code'], 4, '0', STR_PAD_LEFT), 0, 4),
  ));
  if (($row = $result
    ->fetchObject()) !== FALSE) {
    return array(
      'lat' => $row->latitude,
      'lon' => $row->longitude,
    );
  }
  else {
    return NULL;
  }
}