diff --git a/supported/location.au.inc b/supported/location.au.inc index df0c3c8..0dcdd17 100644 --- a/supported/location.au.inc +++ b/supported/location.au.inc @@ -24,14 +24,14 @@ function location_latlon_rough_au($location = array()) { return NULL; } - $result = db_query("SELECT latitude, longitude FROM {zipcodes} WHERE country = '%s' AND zip = '%s'", $location['country'], substr(str_pad($location['postal_code'], 4, '0', STR_PAD_LEFT), 0, 4)); + // Correct the postal code. + $location['postal_code'] = substr(str_pad($location['postal_code'], 4, '0', STR_PAD_LEFT), 0, 4); - if ($row = db_fetch_object($result)) { - return array('lat' => $row->latitude, 'lon' => $row->longitude); - } - else { - return NULL; - } + // This is for the Australia. + $location['country'] = 'au'; + + // Defer to the default logic. + return location_latlon_rough_default($location); } /** diff --git a/supported/location.ca.inc b/supported/location.ca.inc index 4816f7d..d9e4a6b 100644 --- a/supported/location.ca.inc +++ b/supported/location.ca.inc @@ -36,40 +36,6 @@ function location_province_list_numeric_ca() { ); } - - -/** - * Returns a lat/lon pair of the approximate center of the given postal code in the given country - * - * @param $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 - * 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 - * - */ -function location_latlon_rough_ca($location = array()) { - if (!isset($location['postal_code'])) { - return NULL; - } - - $result = db_query("SELECT latitude, longitude FROM {zipcodes} WHERE country = '%s' AND zip = '%s'", $location['country'], $location['postal_code']); - - if ($row = db_fetch_object($result)) { - return array('lat' => $row->latitude, 'lon' => $row->longitude); - } - else { - return NULL; - } -} - /** * Returns a lat/lon pair of the approximate center of the given postal code in the given country * diff --git a/supported/location.no.inc b/supported/location.no.inc index ccab2cc..4d5f602 100644 --- a/supported/location.no.inc +++ b/supported/location.no.inc @@ -24,19 +24,22 @@ function location_province_list_no() { 'VF' => "Vestfold"); } +/** + * Disabled. + */ function _location_latlon_rough_no($location = array()) { if (!isset($location['postal_code'])) { return NULL; } - $result = db_query("SELECT latitude, longitude FROM {zipcodes} WHERE country = '%s' AND zip = '%s'", $location['country'], substr(str_pad($location['postal_code'], 5, '0', STR_PAD_LEFT), 0, 5)); + // Correct the postal code. + $location['postal_code'] = substr(str_pad($location['postal_code'], 5, '0', STR_PAD_LEFT), 0, 5); - if ($row = db_fetch_object($result)) { - return array('lat' => $row->latitude, 'lon' => $row->longitude); - } - else { - return NULL; - } + // This is for Norway. + $location['country'] = 'no'; + + // Defer to the default logic. + return location_latlon_rough_default($location); } /** diff --git a/supported/location.nz.inc b/supported/location.nz.inc index 2ba7ed2..c5875ab 100644 --- a/supported/location.nz.inc +++ b/supported/location.nz.inc @@ -32,3 +32,35 @@ function location_bounds_nz() { 'maxlat' => -8.536767, ); } + +/** + * Returns a lat/lon pair of the approximate center of the given postal code in the given country + * + * @param $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 + * 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 + * + */ +function location_latlon_rough_nz($location = array()) { + if (!isset($location['postal_code'])) { + return NULL; + } + + // Correct the postal code. + $location['postal_code'] = substr(str_pad($location['postal_code'], 4, '0', STR_PAD_LEFT), 0, 4); + + // This is for New Zealand. + $location['country'] = 'nz'; + + // Defer to the default logic. + return location_latlon_rough_default($location); +} diff --git a/supported/location.us.inc b/supported/location.us.inc index 8a1d275..a2a39ad 100644 --- a/supported/location.us.inc +++ b/supported/location.us.inc @@ -22,14 +22,14 @@ function location_latlon_rough_us($location = array()) { return NULL; } - $result = db_query("SELECT latitude, longitude FROM {zipcodes} WHERE country = '%s' AND zip = '%s'", $location['country'], substr(str_pad($location['postal_code'], 5, '0', STR_PAD_LEFT), 0, 5)); + // Correct the ZIP code / postal code. + $location['postal_code'] = substr(str_pad($location['postal_code'], 5, '0', STR_PAD_LEFT), 0, 5); - if ($row = db_fetch_object($result)) { - return array('lat' => $row->latitude, 'lon' => $row->longitude); - } - else { - return NULL; - } + // This is for the USA. + $location['country'] = 'us'; + + // Defer to the default logic. + return location_latlon_rough_default($location); } /**