I recently moved a drupal site from local to host and now geocoding no longer works.
When I go to the location configuration page and go on to the geocoding tab I get the following error:

Notice: Undefined property: stdClass::$data in google_geocode_country_list_xml() (line 17 of /home/truth/www/sites/all/modules/location/geocoding/google.inc).
Notice: Trying to get property of non-object in google_geocode_country_list_xml() (line 24 of /home/truth/www/sites/all/modules/location/geocoding/google.inc).
Notice: Trying to get property of non-object in google_geocode_country_list() (line 54 of /home/truth/www/sites/all/modules/location/geocoding/google.inc).
Warning: Invalid argument supplied for foreach() in google_geocode_country_list() (line 54 of /home/truth/www/sites/all/modules/location/geocoding/google.inc).

How to reproduce a bug #1269914-17: Geocoding no longer working (google.inc)

Does anyone know what's going on here? I've tried everything I can think of (reinstalling modules, new googlemaps api key etc...).
Any help would be appreciated!

Comments

Corbey’s picture

It works perfectly on the local version, does anyone know why this would be?

ankur’s picture

It looks like it's trying to grab the list of countries supported by the Google geocoder, but isn't able to do so for some reason. I'd say check the status page and see if it's possible to check for new updates or, better yet, if there is an error about drupal_http_request() failing. If that's the case, then there's probably an issue with your host being able to send off HTTP requests from within PHP.

Taxoman’s picture

Category: bug » support
Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

summit’s picture

Status: Closed (fixed) » Active

Hi,

I open this again if thats ok. I have the same issue.
May be it has to do with the newer php 5.3 version which my provider has installed?
Other versions than php 5.1.0 seems to have other coding standards?:

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;
}

Greetings, Martijn

millenniumtree’s picture

Also receiving these Undefined property: stdClass::$data in google_geocode_country_list_xml() errors.

We have a CentOS box that can't lookup IP addresses with PHP's fsockopen. For every domain we need the server to look up, we have to put it in the hosts file. Recaptca breaks because of this too.
Try putting spreadsheets.google.com into your /etc/hosts file.

It's a terrible solution, but that's what we have to do for the time being until we can find the real root of the problem.

UPDATE: The problem may be related to IPv6 on the server. Waiting for a config file solution from our hosting provider and I'll post it here. He claims that disabling IPv6 and rebooting will fix the problem. I also found some forum posts indicating that some firewalls can block the NS Lookup packets - but that would presumably block any lookups e.g. 'nslookup', 'ping'.

millenniumtree’s picture

The solution for our CentOS servers (3 of them, experiencing the same issues), was to disable IPv6.

This went in our /etc/modprobe.conf file and then reboot the machine

alias ipv6 off
options ipv6 disable=1
bstrange’s picture

StatusFileSize
new99.74 KB

I am having the same problem, geocoding does not work on any of my sites (over a dozen). This issue does not appear to be exclusive to either D6 or D7 core or their associated location modules. On D6 with Location version 6.x-3.2 it does not download any Google information for the country list or list Google Maps as an option for any country and generates this error:

Type php
Date Tuesday, September 10th, 2013
User (removed by bstrange)
Location http://www.sanduskyspotlight.com/admin/settings/location/geocoding
Referrer http://www.sanduskyspotlight.com/admin/settings/location
Message Invalid argument supplied for foreach() in /home/sandusky/public_html/sites/all/modules/location/geocoding/google.inc on line 54.
Severity error
Hostname (removed by bstrange)
Operations

On Drupal 7, it fails to update geocoding providers, but generates a different set of errors:

• Notice: Undefined property: stdClass::$data in google_geocode_country_list_xml() (line 17 of /home/myseriou/public_html/swcgastro.com/sites/all/modules/location/geocoding/google.inc).
• Notice: Trying to get property of non-object in google_geocode_country_list_xml() (line 24 of /home/myseriou/public_html/swcgastro.com/sites/all/modules/location/geocoding/google.inc).
• Notice: Trying to get property of non-object in google_geocode_country_list() (line 54 of /home/myseriou/public_html/swcgastro.com/sites/all/modules/location/geocoding/google.inc).
• Warning: Invalid argument supplied for foreach() in google_geocode_country_list() (line 54 of /home/myseriou/public_html/swcgastro.com/sites/all/modules/location/geocoding/google.inc)

What is the url it tries to call to obtain the geocoding providers?
Previously, someone had said it was spreadsheets.google.com; however when I bring that up in a browser window it redirects to https://accounts.google.com/ServiceLogin?service=writely&passive=1209600...

I'm not sure what the issue is, and I'm leaning towards a misconfigured setting with my host since it effects all my sites and various versions of Drupal core and the Location module; however, I'd like to point them in the right direction if possible :)

Any help would be greatly appreciated!

hutch’s picture

I've just had a look at geocoding/google.inc.
There is obsolete code in there:
function google_geocode_country_list_xml() stems from the days when google supported a limited set of countries, no longer needed.
function google_geocode_country_list() refers to function google_geocode_country_list_xml(), that needs to be refactored to remove the xml filter.
function google_geocode_location() works fine.
function google_geocode_settings() has obsolete stuff regarding keys which is now no longer a requirement.
There is also a setting for geocoding accuracy which refers to function location_google_geocode_accuracy_codes() which reflects version 2 google API, I see nothing comparable in the docs at https://developers.google.com/maps/documentation/geocoding/
function _google_geocode_flatten() is probably OK

bstrange’s picture

So basically this will require a patch to fix? Or can the error and inability to choose Google Maps as the default geocoding provider be safely ignored?

I have been unable to get gmap displays to show up on any sites that didn't already have Google Maps selected as the default geocoding provider for the United States.

I.e. none of my sites can access the geocoding tab in location without throwing the above errors specific to either D6 or D7 depending on the site; however, many of the sites at one point had Google Maps selected as the default geocoding option and all of those sites can display gmaps. My newer sites cannot choose Google Maps as the default geocoding option for the US and none of those sites display gmap content at all, even when exporting/importing the content type, views, etc that allows gmap to be viewed currently on my sites that previously selected Google Maps as default...

wow that was a mouthful 0.0

hutch’s picture

google.inc needs fixing. On further investigation of the google docs I found that there are accuracy codes so I was wrong about that.

Wouter Van den Bosch’s picture

At the risk of polluting this topic :

I am suddenly having issues with GeoCoding as well. Belgium for me.

About to dig into the code as well now, but might this have something to do with the V2 API's deprecation as of september 9 2013 ?

https://developers.google.com/maps/articles/geocodingupgrade

Had no issues before yesterday. Same codebase.

Wouter Van den Bosch’s picture

Disregard my comment. My issues were due to obselete V2 code and an older version of google.inc

bstrange’s picture

So basically, any new sites will not be able to display Google Maps / gmap data on their site until this is fixed? Without being able to set Google Maps as the default provider for my country in the Geocoding Options, gmap does not display regardless of if I use location + gmap + views, or the older location / node location + location block method (personally, I prefer the views method).

Interestingly, all my sites that were configured to display location / gmap views prior to about June of this year still display their gmaps on location nodes; however, if I click the geocoding options tab on those sites, it returns the same errors, does not list Google Maps under the options column, and lists "No service selected for country." under the configure column.

I'm completely at a loss here as just about every site I have ever built on Drupal has required some utilization of gmap, and currently I can't get any maps to show at all :(

podarok’s picture

Title: Geocoding no longer working » Geocoding no longer working (google.inc)
Component: Miscellaneous » Code
Category: support » task

better title and status

podarok’s picture

Status: Active » Postponed (maintainer needs more info)
bstrange’s picture

StatusFileSize
new156.54 KB

You probably already know this but since you changed the status to 'maintainer needs more info', I thought I'd post it just in case: Unlike #2072869: Google geocoding not always accurate for partial addresses, this error occurs before anything else is configured. I installed Drupal 7, then Location & Gmap and nothing else. Immediately following installation you can click on the Geocoding Options tab and produce this error / see the attached results.

(Off the wall and probably pointless idea) I know when I set up Drupal 7, it gives me a form during install to select the default country... I wonder if I were to leave it as 'None Selected' if it would produce the same error when accessing the admin/config/content/location/geocoding page?

podarok’s picture

Status: Postponed (maintainer needs more info) » Active

thanks

bstrange’s picture

Ok so I found a definitive reason for the errors / inability to download the country / provider table thanks to some help from my hosting company. Per their technician (I have added my own clarifications in brackets):

I found that the geolocation component is trying to connect to Google using IPv6 connection and the IPv6 connections are blocked by CSF firewall in the server and it was causing the problem. I disabled CSF firewall temporarily and the Google Map [here he is referring to the country/provider list for geolocation options] was downloaded successfully. Now the options to select the Google Map [as the default provider for my country] is shown properly. Please note that we have disabled outbound IPv6 connections for security reasons. It cannot be enabled for particular [shared hosting] accounts as it will affect all the other accounts in the server.

After finding this out, I contacted all the major hosting companies and found that none of them allow outgoing IPV6 connections for their shared hosting accounts. As you know, the majority of small to medium sized businesses use shared hosting to avoid the expense of dedicated hosting accounts.

So the big questions are: Is it Google's API that is requiring the connection over IPV6, or is it just the way the code in the Location module is set up? If it is Google, is there a way around it? and if it is the Location module code base, is that something that can be modified? because I would be willing to bet the vast majority of Drupal users utilize shared hosting accounts.

Hope this helps a little, and if I find out anything more from my host, I'll pass it along :)

bstrange’s picture

Issue summary: View changes

Updated issue summary.

ssankarsiva’s picture

Solved , I am using drupal 6 , i had issue on geocode country not listed .
drupal_http_request() replaced in google.inc file . then i got list and working fine using https://drupal.org/project/chr .

rooby’s picture

Category: Task » Bug report
Priority: Normal » Major
Issue summary: View changes

I feel like this is a bug.

dkane’s picture

Has anyone encountered a solution for D7 that doesn't require enabling IPv6 connections on the host?

hutch’s picture

On #21, the 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.

egfrith’s picture

Status: Active » Closed (duplicate)

Thanks hutch. Following your suggestion, I've put a patch at #2406483-12: Gecoding options crash in geocoding/google.inc, which I think is a more appropriate location, as the original bug on this thread was probably different.

flyke’s picture

After a fresh install of the latest location DEV version (7.x-3.x-dev), when going to admin/config/content/location/geocoding I got these errors:

  • Notice: Trying to get property of non-object in google_geocode_country_list() (regel 61 van C:\xampp\htdocs\autov\htdocs\sites\all\modules\contrib\location\geocoding\google.inc).
  • Warning: Invalid argument supplied for foreach() in google_geocode_country_list() (regel 61 van C:\xampp\htdocs\autov\htdocs\sites\all\modules\contrib\location\geocoding\google.inc).

Just like Corbey's screenshots, for most countries, in the options it says 'None supported.'.

This is fixed by editing the file google.inc and replacing the entire function google_geocode_country_list() with just this:

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

Other patches i've seen were for D6 or did not apply without problems, so I wrote my own patch for this.
Hope this helps others with the same problems.

p.s. if you cannot open admin/config/content/location/geocoding because it gives you a white pages with an error, then you probably don't have latest dev version of the module. You can fix this by editing the google.inc file and replacing the line
cache_set('location_google', $xml->asXML());
with this:

if (is_object($xml)) {
        cache_set('location_google', $xml->asXML());
      }

There are 2 instances, so you need to replace both lines.

podarok’s picture

Status: Closed (duplicate) » Patch (to be ported)
Chetna_Negi’s picture

@flyke, your fix for google_geocode_country_list() worked very cleanly. Thanks

Chetna_Negi’s picture

@flyke, your following fix worked very cleanly. Thanks

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

Status: Patch (to be ported) » Needs review

Let's see what testbot currently thinks of the patch.

Status: Needs review » Needs work

The last submitted patch, 25: Location_7_x-3_x-dev__fix_geocoding_options.patch, failed testing.