Same as issue http://drupal.org/node/1940474, but there is no patch for Drupal 6 users. I tried the patches and suggestions mentioned there to no avail.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

podarok’s picture

Title: Google geocoding returned status code: 610 » [6.x-3.x] Google geocoding returned status code: 610
Version: 6.x-3.3-alpha1 » 6.x-3.x-dev
Category: bug » task

better title and Due to #1940474: Google geocoding returned status code: 610 it is a task for backporting

littleneo’s picture

tried to adapt the 7x #27 patch by hand to google.inc with no success. (location 6x-3xdev 17march)

also uh it seems you now need to enable the google map geolocation API feature at code.google.com right ?

I updated the gmap and location modules from 6x-1 to dev as I noticed geolocation was not working anymore this afternoon with the APIv2. until now I never enabled this google map geolocation API feature. Does geolocation works for you using APIv2 (should I downgrade meanwhile ?)

also this ?
https://developers.google.com/maps/documentation/business/geolocation/#u...

littleneo’s picture

ok #27 looks like an attempt to patch a patch.. #2 + $status_code mod. is fine for 6x with the described tweak
geocoding now ok (in france at least (no province field use)).
just removed the gl argument from the query in v7 #2 patch as it does not seem to be an api argument anymore (see)

below a geocoding-working-so-far-with-apiv3 google.inc file for 6x-3xdev from today to review :

( also no need to turn on google map geolocation API feature.. no key anymore in args ? )


/**
 * @file
 * Google geocoder.
 */

/**
 * Returns an XML document containing the list of countries supported by the
 * Google geocoder.
 * A cached version is stored in the Drupal cache in case Google is unreachable.
 */
function google_geocode_country_list_xml() {
  // Get the google data from the feed.
  $source = drupal_http_request('http://spreadsheets.google.com/feeds/list/p9pdwsai2hDMsLkXsoM05KQ/default/public/values');

  if (!$source->data) {
    // Use the cache.
    $data = cache_get('location_google');
    if (!defined('LIBXML_VERSION') || (version_compare(phpversion(), '5.1.0', '<'))) {
      $xml = simplexml_load_string($data->data, NULL);
    }
    else {
      $xml = simplexml_load_string($data->data, NULL, LIBXML_NOERROR | LIBXML_NOWARNING);
    }
  }
  else {
    if (!defined('LIBXML_VERSION') || (version_compare(phpversion(), '5.1.0', '<'))) {
      $xml = simplexml_load_string($source->data, NULL);
      // Stores the XML in the cache to eventually use it later.
      cache_set('location_google', $xml->asXML());
    }
    else {
      $xml = simplexml_load_string($source->data, NULL, LIBXML_NOERROR | LIBXML_NOWARNING);
      // Store the XML in the cache to eventually use it later.
      cache_set('location_google', $xml->asXML());
    }
  }

  return $xml;
}

/**
 * Return the list of ISO3166 codes supported by this geocoder.
 * Coverage list: http://gmaps-samples.googlecode.com/svn/trunk/mapcoverage_filtered.html
 * Coverage list feed: http://spreadsheets.google.com/feeds/list/p9pdwsai2hDMsLkXsoM05KQ/default/public/values
 */
function google_geocode_country_list() {
  // Get the google data from the feed.
  $xml = google_geocode_country_list_xml();

  // Loop through google data and find all valid entries.
  $regionclean = array();
  foreach($xml->entry as $region) {
    $pos = strpos($region->content, 'geocoding:') + 11;
    $geocoding = substr($region->content, $pos, strpos($region->content, ',', $pos) - $pos);
    if (strpos($geocoding, "Yes") !== FALSE) {
     $regionclean[] = t(htmlentities($region->title));
    }
  }

  // Get the countries list and clean it up so that names will match to google.
  // The regex removes parenthetical items so that both of the "Congo" entries
  // and the "Coco Islands" work.
  // The $countriesfixes overwrites values in the Drupal API countries list
  // with values that will match to google's entries.
  // "Sao Tome and Principe" are non-accented in the Drupal API so the entry
  // here is to match the htmlentities() fix in the foreach loop below.
  // Note: it may be neccessary to adjust/add to the fixes list in the future
  // if google adds countries that don't match the Drupal API list for whatever
  // reason.
  $countries = location_get_iso3166_list();
  $regex = "#[ (].*[)]#e";
  $cntryclean = preg_replace($regex, "", $countries);
  $countriesfixes = array_merge($cntryclean, array(
    "hk" => t("China"),
    "mo" => t("China"),
    "pn" => t("Pitcairn Islands"),
    "wf" => t("Wallis Futuna"),
    "st" => t("S&Atilde;&pound;o Tom&Atilde;&copy; and Pr&Atilde;&shy;ncipe"),
  ));

  // Compare new google data found to fixed country name values and return
  // matches with abbreviations as keys.
  $googlematched = array_intersect($countriesfixes, $regionclean);

  // Compare new keys to original Drupal API and return the array with the
  // original name values.
  $fixedkeys = array_intersect_key($countries, $googlematched);
  return array_keys($fixedkeys);
}

/**
 * Return general information about this geocoder.
 */
function google_geocode_info() {
  return array(
    'name' => 'Google Maps',
    'url' => 'http://maps.google.com',
    'tos' => 'http://www.google.com/help/terms_local.html',
    'general' => TRUE,
  );
}

/**
 * Perform a geocode on a location array.
 * @param $location
 *   The location array to process.
 * @return
 *   an associative array with keys 'lat' and 'lon' containing the coordinates.
 */
function google_geocode_location($location = array()) {

  $query = array(
    'address' => _google_geocode_flatten($location),
	'sensor' => 'false',
  );


  $url = url('http://maps.googleapis.com/maps/api/geocode/json', array(
    'query' => $query,
    'external' => TRUE,
  ));

  $http_reply = drupal_http_request($url);
  
  $data = json_decode($http_reply->data);
  
   $status_code = $data->status;
   if ($status_code != 'OK') {
    watchdog('location', 'Google geocoding returned status code: %status_code for the query url: %url', array('%status_code' => $data->status, '%url' => $url));
    return NULL;
   }
   
   $location = $data->results[0]->geometry->location;
   return array('lat' => $location->lat, 'lon' => $location->lng);
}

/**
 * General settings for this geocoder.
 */
function google_geocode_settings() {
  $form = array();
  $key = '';
  if (function_exists('gmap_get_key')) {
    $key = gmap_get_key();
  }

  if (!empty($key)) {
    $form['location_geocode_google_apikey'] = array(
      '#type' => 'item',
      '#title' => t('Google Maps API Key'),
      '#value' => $key,
      '#description' => t('The key in use was automatically provided by GMap.'),
    );
  }
  else {
    $form['location_geocode_google_apikey'] = array(
      '#type' => 'textfield',
      '#title' => t('Google Maps API Key'),
      '#size' => 64,
      '#maxlength' => 128,
      '#default_value' => variable_get('location_geocode_google_apikey', ''),
      '#description' => t('In order to use the Google Maps API geocoding web-service, you will need a Google Maps API Key.  You can obtain one at the !sign_up_link for the !google_maps_api.  PLEASE NOTE: You will <em>not</em> have to re-enter your API key for each country for which you have selected Google Maps for geocoding.  This setting is global.', array('!sign_up_link' => '<a href="http://www.google.com/apis/maps/signup.html">sign-up page</a>', '!google_maps_api' => '<a href="http://www.google.com/apis/maps/">Google Maps API</a>'))
    );
  }

  $country = arg(4);
  if ($country) {
    $form['location_geocode_' . $country . '_google_accuracy_code'] = array(
      '#type' => 'select',
      '#title' => t('Google Maps Geocoding Accuracy for %country', array('%country' => $country ) ),
      '#default_value' => variable_get('location_geocode_' . $country . '_google_accuracy_code', variable_get('location_geocode_google_minimum_accuracy', '3')),
      '#options' => location_google_geocode_accuracy_codes(),
      '#description' => t('The minimum required accuracy for the geolocation data to be saved.'),
    );
  }
  return $form;
}

function _google_geocode_flatten($location = array()) {
  // Check if its a valid address
  if (empty($location)) {
    return '';
  }

  $address = '';
  if (!empty($location['street'])) {
    $address .= $location['street'];
  }

  if (!empty($location['city'])) {
    if (!empty($address)) {
      $address .= ' ';
    }
    $address .= $location['city'];
  }

  if (!empty($location['province'])) {
    if (!empty($address)) {
      $address .= ' ';
    }

    // @@@ Fix this!
    if (substr($location['province'], 0, 3) == $location['country'] . '-') {
      $address .= substr($location['province'], 3);
      watchdog('Location', 'BUG: Country found in province attribute.');
    }
    else {
      $address .= $location['province'];
    }
  }

  if (!empty($location['postal_code'])) {
    if (!empty($address)) {
      $address .= ', ';
    }
    $address .= $location['postal_code'];
  }

  if (!empty($location['country'])) {
    if (!empty($address)) {
      $address .= ' ';
    }
    $address .= $location['country'];
  }

  return $address;
}
littleneo’s picture

Status: Active » Needs review
podarok’s picture

Status: Needs review » Needs work

please, do upload a patch against latest 6.x-3.x-dev. not a code via comment post.

littleneo’s picture

sorry I would have if I was used to. got no time and doesn't know GNU patch very well. just replace entirely the file.

dunx’s picture

FileSize
2.77 KB

Here's a patch for 3.2 for those that need it now.

dunx’s picture

FileSize
2.77 KB

I think this patch will do for -dev, but I can't test it.

dunx’s picture

Just to clarify; both the above patches are for location/geocoding/google.inc

rougekris’s picture

I patched my Location module (6.x-3.x) with the instructions in the corresponding 7.x issue. I had to do it manually of course, but it works perfectly.

Something I need to mention though is that when you're fixing the information in the content/profiles, you need to enter a different postal code or otherwise Location won't change the geocoding. I was going in to content and saving it, but that's not enough.

podarok’s picture

Status: Needs work » Needs review

bot

Status: Needs review » Needs work

The last submitted patch, location6-3-dev.patch, failed testing.

podarok’s picture

patch is in wrong format
look at http://drupal.org/patch

dunx’s picture

Ah, yes should have used -p1 format. Sorry, but deleted all my working files now, so can't quickly reproduce.

In the meantime, I guess all D6 location geocoding has stopped working.

manoloka’s picture

Patch of post #2 and comment #9 from http://drupal.org/node/1940474 solved the issue for me.

I'm and I'm on D6 (even though the post is for D7)

podarok’s picture

#15 can You upload patch against latest dev

johnlutz’s picture

Went off of dunx's changes and they worked, so just patched dev correctly (I hope)

johnlutz’s picture

Status: Needs work » Needs review
podarok’s picture

Status: Needs review » Needs work
+++ b/geocoding/google.incundefined
@@ -119,45 +119,28 @@ function google_geocode_location($location = array()) {
-    'key' => $key,
+	'gl' => $location['country'],

tabstops should be spaces errors

+++ b/geocoding/google.incundefined
@@ -119,45 +119,28 @@ function google_geocode_location($location = array()) {
+  ¶
+  $data = json_decode($http_reply->data);
+++ b/geocoding/google.incundefined
@@ -119,45 +119,28 @@ function google_geocode_location($location = array()) {
+  $location = $data->results[0]->geometry->location;
+ ¶
+  return array('lat' => $location->lat, 'lon' => $location->lng);

trailing whitespaces errors

http://drupal.org/coding-standards#indenting

webservant316’s picture

The patch at #17 works for me. I needed to re-save each node to get the map to reset by changing something on the location such as the zipcode and then changing it back. Anyone know of a better way to do that???

rougekris’s picture

#20:

I already mentioned this in #10. It's vital though, and should probably be in the patch notes somewhere.

webservant316’s picture

#20, yep. But does anyone know of a better way to do that than re-saving each node? I took me an hour to go through all my nodes. Seems like there ought to be an automatic means to do that.

rougekris’s picture

I understand why the functionality is in place, but it was a pain on this occasion. Thankfully, it was an issue on a site that isn't teeming with activity, so I only had five or six users to re-edit.

My understanding of the module, from a code standpoint (having gone through the same issue you did), is that manually re-geocoding each node/user/entity is the only way to go. It's useful for 99.9% of the time except for now.

podarok’s picture

due to #19 and especially #20 this needs work

ellastelter’s picture

Status: Needs work » Fixed

Yay! #17 worked for me. Thanks everyone!

webservant316’s picture

The cumbersome node re-saving related to #20 isn't a deficiency in the patch, but only that the location module doesn't have a means to force the re-geocoding of all or select locations. It is further complicated because the location module assumes that unless the text of the address changes, there is no need to recalculate. This seems like a logical thing to do, however, if you want to force a recalculation you can only do that by changing the address, saving, then changing it back again, and re-saving.

Perhaps a checkbox could be added that indicates to re-geocode on the save of a node or user regardless. Perhaps also add an administrative function to re-geocode all locations. I will create a feature request issue for these ideas.

http://drupal.org/node/1948640
http://drupal.org/node/1948642

podarok’s picture

Status: Fixed » Needs work

its not fixed

Anonymous’s picture

Patch in #17 worked for me. Ensure you have the Geocoding API enabled in your Google API settings.

johnlutz’s picture

Status: Needs work » Needs review
FileSize
3.03 KB

Updated patch per comments in #19.

podarok’s picture

Status: Needs review » Fixed

#29 commited pushed to 6.x-3.x
thanks!!!

podarok’s picture

Status: Fixed » Closed (fixed)

tagged new beta release
http://drupal.org/node/1949934