### Eclipse Workspace Patch 1.0
#P drupal6
Index: sites/all/modules/location/geocoding/google.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/location/geocoding/google.inc,v
retrieving revision 1.11.2.3
diff -u -r1.11.2.3 google.inc
--- sites/all/modules/location/geocoding/google.inc	29 Jun 2009 14:11:16 -0000	1.11.2.3
+++ sites/all/modules/location/geocoding/google.inc	10 Mar 2010 20:00:54 -0000
@@ -125,25 +125,33 @@
   ));
 
   $http_reply = drupal_http_request($url);
-
-  $status_code_match = array();
-  preg_match('/<code>(.*)<\/code>/', $http_reply->data, $status_code_match);
-  $status_code = $status_code_match[1];
-  if ($status_code != 200) {
-    return NULL;
-  }
-
-  $accuracy_code_match = array();
-  preg_match('/Accuracy="([0-9])"/', $http_reply->data, $accuracy_code_match);
-  $accuracy_code = $accuracy_code_match[1];
-  if ($accuracy_code < 3) {
+//  dpr($http_reply->data);
+  libxml_use_internal_errors(true);
+  $xml = simplexml_load_string($http_reply->data);
+  $pars = '$a,&$b,$c';
+  $recurse = '
+    foreach($a->attributes()as$f=>$g)
+      $b[$f]=(string)$g;
+    foreach($a->children()as$d=>$e){
+      $b[$d]=trim((string)$e);
+      @$c($e,$b,$c);
+    }
+  ';
+  $data = array();
+  $func = create_function($pars, $recurse);
+  $func($xml->Response, $data, $func);
+  $data = array_filter($data, create_function('$a', 'return!empty($a);'));
+  if ($err = libxml_get_last_error()) {
+    //TODO watchdog
+    libxml_clear_errors();
+  }
+  dpm($data);
+  if ($data['code'] != 200 ||
+      $data['Accuracy'] < 3 ||
+      strcasecmp($data['CountryNameCode'], $location['country']) != 0) {
     return NULL;
   }
-
-  $latlon_match = array();
-  preg_match('/<coordinates>(.*)<\/coordinates>/', $http_reply->data, $latlon_match);
-
-  $latlon_exploded = explode(',', $latlon_match[1]);
+  $latlon_exploded = explode(',', $data['coordinates']);
 
   return array('lat' => $latlon_exploded[1], 'lon' => $latlon_exploded[0]);
 }
