Adding google geocoding for various countries.
authorAnkur Rishi
Thu, 2 Aug 2007 04:34:10 +0000 (04:34 +0000)
committerAnkur Rishi
Thu, 2 Aug 2007 04:34:10 +0000 (04:34 +0000)
geocoding/google.inc

index 2d185a3..1008eb2 100644 (file)
@@ -6,8 +6,17 @@ function google_geocode_country_list() {
   
   if (!count($countries)) {
     $countries = array(
+      'br',
       'ca',
+      'cz',
+      'de',
       'fr',
+      'hu',
+      'in',
+      'pl',
+      'pt',
+      'sg',
+      'tw',
       'us',
       'uk'
     );
@@ -28,25 +37,34 @@ function google_geocode_info() {
 }
 
 function google_geocode_location($location = array()) {
+  
+  switch ($location['country']) {
+    case 'uk':
+      if ($location['street'] && $location['city']) {
+        unset($location['postal_code']);
+      }
+      elseif ($location['postal_code']) {
+        unset($location['city']);
+        unset($location['street']);
+        unset($location['additional']);
+      }
+      else {
+        unset($location['postal_code']);
+      }
+      $query = location_address2singleline($location);
+      break;
+    default:
+      $query = location_address2singleline($location);
+      break;
+  }
+  
   if ($location['country'] == 'uk') {
-    if ($location['street'] && $location['city']) {
-      unset($location['postal_code']);
-    }
-    elseif ($location['postal_code']) {
-      unset($location['city']);
-      unset($location['street']);
-      unset($location['additional']);
-    }
-    else {
-      unset($location['postal_code']);
-    }
+
   }
 
   $service_url = 'http://maps.google.com/maps/geo?output=xml&key='. variable_get('location_geocode_google_apikey', '') .'&q=';
-
-  $address = location_address2singleline($location);
   
-  $http_reply = drupal_http_request($service_url . urlencode($address));
+  $http_reply = drupal_http_request($service_url . urlencode($query));
   
   $status_code_match = array();
   preg_match('/<code>(.*)<\/code>/', $http_reply->data, $status_code_match);