Notice: Trying to get property of non-object in GoogleGeocode->read() (line 51 of .../sites/all/libraries/geoPHP/lib/adapters/GoogleGeocode.class.php).

I get this error every time that I save a node containing an addressfield that I am trying to geocode into a geofield.

Comments

tlattimore’s picture

I am also getting this same error...

nod_’s picture

Does it takes a really long time to save and fail ? I had this because of a connection timeout.

tlattimore’s picture

@nod_ In my case it doesn't take a long to to save and fail. It just fails.

odavy’s picture

I'm getting this as well, every time.

goron’s picture

I'm also getting this error on every node save. Geocodes are not saved.

goron’s picture

Interestingly, I get this error only on my dev site on my server. It works fine locally. The URL for the request is being built fine, but it doesn't seem to return anything. Could this have something to do with server configuration? Are others on this page getting this problem in live environments too?

goron’s picture

Status: Active » Fixed

Ok. I figured it out.

It's a PHP setting called allow_url_fopen that needs to be on for the request method that file uses to work. In my server configuration it was off. You can turn it on in your php.ini file.

If you don't have access to your php.ini - I'm not sure if you can set that variable at runtime. Maybe with putenv()?

You can also solve this by changing the method used to do the request. Change the code in line 49 of GoogleGeocode.class.php from:
$this->result = json_decode(@file_get_contents($url));
to:
$this->result = json_decode(drupal_http_request($url)->data);

odavy’s picture

Status: Fixed » Needs work

Just tried making the change in code you mention, restarted all services and cleared the cache, tried to create a new node and got the following error:

    Notice: Undefined property: stdClass::$data in GoogleGeocode->read() (line 49 of C:\wamp\www\geo\sites\all\libraries\geoPHP\lib\adapters\GoogleGeocode.class.php).
    Notice: Trying to get property of non-object in GoogleGeocode->read() (line 51 of C:\wamp\www\geo\sites\all\libraries\geoPHP\lib\adapters\GoogleGeocode.class.php).

It did save the node though, just didn't do the geocode.

burgs’s picture

I too have allow_url_fopen enabled, but am getting the non-object error on line 51 as per the above comment. It does seem to be only on certain occasions that it will fail though.
I have narrowed the problem down to the fact that file_get_contents isn't working for some reason. I can browse to the url it generates though, so I'll keep looking.

vasike’s picture

indeed the #7 save the day, but this seems to be a geoPHP issue not a Geocoder one.

michaelfavia’s picture

Status: Needs work » Closed (fixed)

Issue resolved? Please reopen if this is found to be geocoder and not geophp.

hampshire’s picture

Status: Closed (fixed) » Active

I had this working and then it stopped with the above line 51 error. The only thing I can think of that I changed was installing the Gmap module. If I use Yahoo Placefinder to geocode that works but is not very accurate so I would prefer google. Any thoughts.

goron’s picture

Have you tried uninstalling Gmap and seeing if you still get the error?

hampshire’s picture

No as it is now vital to the part of my site that is working but I just wanted to throw it out there and see if anyone else had similar issues though I did not see anyone else who had it working then had it stop working. I will try to clone the site and uninstall gmaps this weekend however and report back.

kvit’s picture

Had the same error.
Changing GoogleGeocode.class.php as described in #7 solved it. Thanks

hampshire’s picture

Status: Active » Closed (fixed)

Went to test mine over the weekend and google just worked again, no need for the fix in #7 or any changes. Perhaps there was an issue with google itself the last time I was working on it.

R.J. Steinert’s picture

This error occurs when the server requesting the coordinates from google does not receive a response which could be due to a timeout, or in my case my server didn't have access to google.com. The library from Google does not check if the response came back alright so folks are currently stuck with that non descriptive error. Ideally if the lookup fails, I think we should trigger some kind of error like "Address lookup failed. Try resubmitting." I'm not sure if we should patch geoPHP or the geocoder module...

Bug filed on geoPHP github https://github.com/phayes/geoPHP/issues/16

phayes’s picture

Status: Closed (fixed) » Needs review

This has been fixed in geoPHP. geoPHP now throws an exception. I believe that geocoder module checks for this and handles it, but I think it needs some verificaiton.

phayes’s picture

Status: Needs review » Fixed

I've confirm that geocoder can deal with this. Marking as fixed

Status: Fixed » Closed (fixed)

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