Index: supported/location.uk.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/location/supported/location.uk.inc,v
retrieving revision 1.7
diff -u -p -r1.7 location.uk.inc
--- supported/location.uk.inc	8 Mar 2008 18:55:18 -0000	1.7
+++ supported/location.uk.inc	5 Feb 2011 00:56:57 -0000
@@ -254,17 +254,119 @@ function location_map_link_uk_default_pr
 
 function location_map_link_uk_google($location = array()) {
   $query_params = array();
+  $q = NULL;
 
-  foreach (array('street', 'city', 'postal_code', 'country') as $field) {
+  foreach (array('street', 'city', 'province', 'postal_code', 'country') as $field) {
     if (isset($location[$field])) {
       $query_params[] = $location[$field];
     }
   }
 
-  if (count($query_params)) {
-    return ('http://maps.google.co.uk?q='. urlencode(implode(', ', $query_params)));
+  if (location_has_coordinates($location)) {
+    $q = $location['latitude'] .' '. $location['longitude'];
+    if (count($query_params) > 0) {
+      $q .= ' ('. implode(', ', $query_params) .')';
+    }
+    $q = urlencode($q);
+  } else if (count($query_params) > 0) {
+    $q = urlencode(implode(", ", $query_params));
+  }
+
+  if ($q != NULL) {
+    return ('http://maps.google.co.uk?q='.$q );
+  }
+  else {
+    return NULL;
+  }
+}
+
+/**
+ * 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_uk($location = array()) {
+  // sanity checks
+  if (!isset($location['postal_code']) || empty($location['postal_code']) || !isset($location['country']) || empty($location['country'])) {
+    return NULL;
+  }
+  if (! db_table_exists('zipcodes')) {
+    return NULL;
+  }
+
+  // Now we query.
+  $result = db_query("SELECT latitude, longitude FROM {zipcodes} WHERE country = '%s' AND zip = '%s'", $location['country'], preg_replace('/\s+/', '', $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,
+ * plus the city, province and country entries.
+ *
+ * @param $location
+ *   An associative array $location where only postal code and country are necessary, but can have the keys:
+ *     '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
+ *      'city' => city entry in the database
+ *      'province' => province entry in the database
+ *      'country' => country entry in the database
+ */
+function location_get_postalcode_data_uk($location = array()) {
+  // sanity checks
+  if (!isset($location['postal_code']) || empty($location['postal_code']) || !isset($location['country']) || empty($location['country'])) {
+    return NULL;
+  }
+  if (! db_table_exists('zipcodes')) {
+    return NULL;
+  }
+
+  // Now we query.
+  $result = db_query("SELECT * FROM {zipcodes} where country = '%s' AND zip = '%s'", $location['country'], preg_replace('/\s+/', '', $location['postal_code']));
+  if ($row = db_fetch_object($result)) {
+    return array('lat' => $row->latitude, 'lon' => $row->longitude, 'city' => $row->city, 'province' => $row->state, 'country' => $row->country);
+  }
+  else {
+    return NULL;
+  }
+}
+
+/**
+ * Parameters:
+ *   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)
+ *
+ *
+ */
+function location_latlon_exact_uk($location = array()) {
+  return NULL;
+  // someday when Royal Mail et al let go of their monopoly.....
+}
