Hi guys,

It seems the admin/config/content/location/geocoding URL is not working anymore.

When I try to access the page I got an error in function function google_geocode_country_list_xml() {}

Error happens only if you don't have previously cached values for the country list.

As i found out the issue is with the http://spreadsheets.google.com/feeds/list/p9pdwsai2hDMsLkXsoM05KQ/defaul... URL which is not accessible for me.

Does this spreadsheet has some country based restriction or something? If yes, it doesn't work from UK.

The error in php returned is:
Fatal error: Call to a member function asXML() on a non-object in /Library/WebServer/Documents/WORKSPACE/opencommerce/sites/all/modules/contrib/location/geocoding/google.inc on line 38

Error when I debug the http_request call:

stdClass Object
(
[data] => You do not have view access to the spreadsheet. Make sure that you are properly authenticated.
[errno] => 0
[redirect_url] => http://spreadsheets.google.com/feeds/list/p9pdwsai2hDMsLkXsoM05KQ/defaul...
[request] => GET /feeds/list/p9pdwsai2hDMsLkXsoM05KQ/default/public/values HTTP/1.1
User-Agent: Drupal (+http://drupal.org/)
Accept: */*
Host: spreadsheets.google.com

[protocol] => HTTP/1.1
[status_message] => Forbidden
[headers] => Array
(
[content-type] => text/html; charset=UTF-8
[set-cookie] => NID=67=XjgNL60BY3V5lQY1Vh_N60qyuQrur8rb5moyU4qLXqe6D8Q1ZzDvd_8hP_t9yUsNsYwIIlJZlqBQe3YDwSVyjBdXP2b0lE0xfy5XWADw_FHlxLIyhMTYsSqdgWTBV9bX;Domain=.google.com;Path=/;Expires=Wed, 15-Jul-2015 12:14:10 GMT;HttpOnly
[p3p] => CP="This is not a P3P policy!

Files: 
CommentFileSizeAuthor
#48 location-google_geocoding-2406483-48-d6.patch3.92 KBjojonaloha
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch location-google_geocoding-2406483-48-d6.patch. Unable to apply patch. See the log in the details link for more information. View
#12 google_geocoding-2406483-12.patch3.87 KBegfrith
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch google_geocoding-2406483-12.patch. Unable to apply patch. See the log in the details link for more information. View

Comments

randomyao22’s picture

I met this exactly same error today too. It works two days ago. I'm in Australia.
As greg_meszaros said above, need some one have a look at why this google feed not available any more, which is in geocoding/google.inc.
http://spreadsheets.google.com/feeds/list/p9pdwsai2hDMsLkXsoM05KQ/defaul...

pog21’s picture

Same problem here. Trying to access the google spreadsheet results in 403 forbidden.

randomyao22’s picture

I think my local site has a cache so it is still working. Is there a way to find the local cached country list data and copy them to my server site? I tried cache_get('location_google'), but I can get nothing.

randomyao22’s picture

Before someone can fix it, I find a way to temporary make my site work.

I tried to find the location geocode data in my local site database(Which is installed before bug happened) and find these useful for me. Added following data to my new site's database, make it works now. This is just temporary solution, make my store locator work. Still waiting for module developer to fix this bug.

INSERT INTO `variable` (`name`, `value`) VALUES
('location_geocode_google_minimum_accuracy', 0x733a313a2233223b);
INSERT INTO `variable` (`name`, `value`) VALUES
('location_general_geocoders_in_use', 0x613a313a7b733a363a22676f6f676c65223b733a363a22676f6f676c65223b7d);

INSERT INTO `variable` (`name`, `value`) VALUES
('location_geocode_nz', 0x733a363a22676f6f676c65223b);
INSERT INTO `variable` (`name`, `value`) VALUES
('location_geocode_au', 0x733a363a22676f6f676c65223b);
INSERT INTO `variable` (`name`, `value`) VALUES
('location_geocode_jp', 0x733a343a226e6f6e65223b);
INSERT INTO `variable` (`name`, `value`) VALUES
('location_geocode_us', 0x733a343a226e6f6e65223b);
falc0’s picture

boomman14’s picture

#5 works for temp fix. Thanks falc0.

dkane’s picture

Falc0: I swapped out the url in $source = drupal_http_request in google.inc to the one above and now Google maps is showing up in my geocoder list, but it still doesn't seem to be geocoding new locations. Did I miss a step?

joegl’s picture

Having the same issue. Getting a Fatal Error when trying to access the Geocoding Settings page. Co-worker says it was working fine a few days ago.

dkane’s picture

Joegl. I was getting the fatal error as well. https://www.drupal.org/node/1070644#comment-8007895 helped me solve that.

Now I'm able to access and save settings, but new locations are still not geocoding.

joegl’s picture

I was able to access the page by updating the spreadsheet URL to the web.archive.org link in comment #5 (thanks falc0). This got rid of the fatal error. I was also able to finally generate lat/lon for my content types, but I'm having an issue with using the full province/state name versus the abbreviation. I will be opening a new issue for that.

hyperlinked’s picture

The web.archive.org link will fix the WSOD issue. Now here's a workaround you can use to grab the geocode coordinates in a hook_node_presave function. Just drop this into a custom module. You can just do your own lookup to get the geocoordinates.

You can also adapt this to work as part of a locationapi save action or a hook_user_presave if you need to do the geocoding directly on a location because you're not always handling locations as part of a node save.

/*
 * Location Geo-code grabber presave hook
 */
function lgg_node_presave($node) {
	global $bypass_location_presave;
	
	if (isset($node->locations)) {	
		$location = $node->locations[0];
		
		$address = $location['street'].' '.$location['city'].' '.$location['province'].' '.$location['postal_code'].' '.$location['country'];
		$address = urlencode($address);
	
		$requesturl = 'http://maps.googleapis.com/maps/api/geocode/json?address='.$address.'&sensor=true';

		$return = drupal_http_request($requesturl);
	
		$data = json_decode($return->data);
	
		if ($data->results[0]) {		
			$location['latitude'] = round($data->results[0]->geometry->location->lat,6);
			$location['longitude'] = round($data->results[0]->geometry->location->lng,6);
			$location['source'] = 3;
			$location['inhibit_geocode'] = TRUE;
			$node->locations[0] = $location;
			return $node;		
		}	
	}
}	
egfrith’s picture

Status: Active » Needs review
FileSize
3.87 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch google_geocoding-2406483-12.patch. Unable to apply patch. See the log in the details link for more information. View

At #1269914-23: Geocoding no longer working (google.inc) hutch comments:

function google_geocode_country_list_xml() in google.inc is obsolete, Google no longer do their geocoding on a per-country basis so function google_geocode_country_list() needs to just return the $countries variable. If you want to let admins munge the countries list then provide support for the countries module.

The attached patch removes google_gecode_country_list_xml() and gets google_ google_geocode_country_list() to return the keys of location_get_iso3166_list().

egfrith’s picture

Title: Issue with geocoding/google.inc » Gecoding options crash in geocoding/google.inc
pog21’s picture

#12 worked for me. Thanks for patch.

PhilY’s picture

patch #12 worked for me, thanks

liezie_D’s picture

applying this patch gives me a new error :
Notice: Undefined variable: countries in google_geocode_country_list()
(regel 17 van C:\\sites\all\modules\location\geocoding\google.inc).

UPDATE: nevermind.. i manually patched and missed a line..

egfrith’s picture

Hmm... Just to check the patch has worked as intendended, does google_geocode_country_list() in C:\sites\all\modules\location\geocoding\google.inc look like this:

function google_geocode_country_list() {
  $countries = location_get_iso3166_list();
  return array_keys($countries);
}

?

liezie_D’s picture

@egfrith: it's fixed. i had accidentaly also removed the line that starts with "$countries ... "

joegl’s picture

I am on 3.x.2 so the patch does not work for me. However, for people in a similar boat all you need to do is replace the google_geocode_country_list() function in google.inc with this code:

function google_geocode_country_list() {
  $countries = location_get_iso3166_list();
  return array_keys($countries);
}
anacat’s picture

Only local images are allowed.Hi guys !

I used the patch, I don't have any errors.
But I still don't get the options or configure part, most of them say "none supported" and "No service selected for country."

What am I missing ?

joegl’s picture

I am not sure #20 since I setup mine following instructions from another site.

Do you have the gmap and gmap_location modules? Not sure if they're necessary but might be.

You also might want to go to this page: admin/config/content/location/util and clear both of the cache's.

anacat’s picture

Hi Joegl,

Thanks for the repply :)

Yes I have both modules enabled and I followed your suggestions but nothing changed :/
I dont know if it helps but I only find options from Canada, new zealand, united states. And the options are: "none", "Yahoo! Maps Web Services (Terms of Use)"
and no google maps button option like it was before this bug.

joegl’s picture

Do you have an Google maps API Key? I don't think it's necessary but might help.

Also, on the Main Settings page for the Location module do you have the "use a google map to set latitude and longitude" checkbox checked?

Wish I could help more. It sounds like that even though you have the patch it still isn't loading the countries properly but I could be wrong.

anacat’s picture

So I did the things you suggested (actually they were missing, thanks! :) ) but still no changes.

I get the page geocoding options working (it takes a bit to long to load) but then almost all countries say something like:

Example.: Afghanistan None supported. No service selected for country.

anacat’s picture

Nevermind ! I did it all over again following all steps and now its working.

Thanks everybody for the great comments/problem solving discussion & solutions. :)

PJnes’s picture

The patch in #12 works for me as well.

Can we get this rolled in to a new release?

drummondf’s picture

#12 worked for me, thank you.

Should this be commited or does it have "side effects?"

joegl’s picture

Patch is no worse than the current Fatal Error being served and preventing the page from loading. As far as I know no funny business.

drummondf’s picture

One thing I noticed (and it may be from somewhere else in my config) but Google Maps is no longer an option for geocoding? Only Yahoo Maps. Does anyone else have this side effect?

egfrith’s picture

@drummondf On admin/config/content/location/geocoding I have a long list of countries. For every country Google Maps is an option. For New Zealand, Australia and the USA, Yahoo is also an option. Is the behaviour you see different from this?

drummondf’s picture

@egfrith yes, I get "none supported" for nearly everything except Australia (Yahoo Maps), Canada (GeoCode.ca) and US (Yahoo Maps)

The only thing non-standard with my install is the patch in #12 above.

I have toggled the "Use a Google Map to set latitude and longitude" at /admin/config/content/location and both settings returned the above results.

netgeek123’s picture

ran patch and it fails...

patch < google_geocoding-2406483-12.patch
patching file google.inc
Hunk #1 FAILED at 6.
1 out of 1 hunk FAILED -- saving rejects to file google.inc.rej

reject file...

***************
*** 6,100 ****
   */
  
  /**
-  * 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 = "#[ (].*[)]#";
-   $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);
  }
  
  /**
--- 6,19 ----
   */
  
  /**
+  * Return the list of ISO3166 codes supported by this geocoder. 
+  * 
+  * Google now supports geocoding for all countries:
+  * https://developers.google.com/maps/coverage
   */
  function google_geocode_country_list() {
    $countries = location_get_iso3166_list();
+   return array_keys($countries);
  }
  
  /**

egfrith’s picture

@drummondf: Is the gmap module enabled on your site? The docs suggest it is needed for geocoding:
https://www.drupal.org/documentation/modules/location

netgeek123’s picture

DOH!

drummondf’s picture

@egfrith it is installed, enabled, configured properly and displaying maps in other forms

flyke’s picture

Patch #12 works for me

podarok’s picture

Status: Needs review » Fixed

#12 commited
Thanks!

  • podarok committed b698f43 on 7.x-3.x authored by egfrith
    Issue #2406483 by egfrith: Gecoding options crash in geocoding/google....
RonP’s picture

I am trying to build a site and am running into this error. Is it fixed in the released build ? I have no idea how to patch a module.

Thank you

pog21’s picture

@RonP There is information on patching here: https://www.drupal.org/patch/apply. This would be appied against 7.x-3.6.

But by the looks of things, you can update to the latest dev (7.x-3.x-dev) which now has the patch applied (see #38, #39, above).

Szerge’s picture

@pog21: updated to 7.x-3.x-dev and I now have a blank page at admin/config/content/location/geocoding. Eearlier #12 fixed the blank page but not the geocoding. I created a module with #11 but I must have missed a step as there was still no geocoding...

pog21’s picture

@Szerge, I am still using the patched 7.x-3.6 and it seems fine. So other than rolling back (completely - i.e. uninstalling/deleting directory/flushing caches like crazy) and patching (correctly, via command line), I don't really know what to suggest.

Szerge’s picture

@pog21, thank you. I've now installed Location 7.x-3.7-beta1 and admin/config/content/location/geocoding displays the list of countries and I can select Google to perform the geocoding for the different countries. The only thing is that no geocoding seems to be performed... Although not mandatory, I've a valid key, to no effect. So, no more white page but no geocoding....

I remember clearly with a working version (months ago!) that when I selected the country, one second later the lat/lon fields were automatically filled-in. Not anymore :-(

joegl’s picture

Did you clear cache? Do you have the gmap and gmap_location modules installed? Did you disable and re-enable the module after patching? I don't think the WSOD has been reported for this issue yet.

joegl’s picture

Did you clear cache? Do you have the gmap and gmap_location modules installed? Did you disable and re-enable the module after patching? I don't think the WSOD has been reported for this issue yet.

robdubparker’s picture

Any chance if this patch being committed to Drupal 6.x version?

jojonaloha’s picture

Version: 7.x-3.6 » 6.x-3.x-dev
Status: Fixed » Needs review
FileSize
3.92 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch location-google_geocoding-2406483-48-d6.patch. Unable to apply patch. See the log in the details link for more information. View

Attached is a re-roll of the patch from #12, committed in #39 for the 6.x-3.x branch.

pog21’s picture

#48 worked for me. Thanks for the patch.

caspervoogt’s picture

I'm on D7 and #12 works for me.

The last submitted patch, 12: google_geocoding-2406483-12.patch, failed testing.

jeffschuler’s picture

@plethoradesign: #12 was already committed to the D7 version (see comment #38).
Just download the 7.x-3.x-dev version of the module.

caspervoogt’s picture

thanks Jeff. Not sure what I did. Maybe I had applied it to 7.x-3.6 or something.

  • podarok committed 6f37696 on 6.x-3.x authored by jojonaloha
    Issue #2406483 by egfrith, jojonaloha: Gecoding options crash in...
podarok’s picture

Status: Needs review » Fixed

##4 commited
Thanks

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Status: Closed (fixed) » Needs review

Status: Needs review » Needs work

The last submitted patch, 48: location-google_geocoding-2406483-48-d6.patch, failed testing.

JeroenT’s picture

Status: Needs work » Closed (fixed)
tinem’s picture

So all here in this discussion are using 6.x-3.x-dev and have no problems? If this is the case shouldn't this version be recommended instead of 6.x-3.4?

Not sure you have seen my post https://www.drupal.org/node/2540086 asking for help, please?