Title: google maps api curl call
Last modified: August 21, 2016

---

# google maps api curl call

 *  Resolved [carterconnection21](https://wordpress.org/support/users/carterconnection21/)
 * (@carterconnection21)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/google-maps-api-curl-call/)
 * The curl call you have reaching out to google trying trying to pull back the 
   lat and log doesnt return anything even though the url generated is correct. 
   The error checking is there but the line after tries to get this $addr_search_1-
   >results[0]->geometry->location
 * Two things:
 * 1. If its empty then it kicks a PHP error because the results property doesnt
   exist.
 * 2. The results object that comes back from google isn’t an array.
 * This causes the user’s information entered while trying to create a listing to
   be lost, because of the php error mentioned above the script can’t continue to
   the bepro_add_post function.
 * Version 2.0.84
    I’m a geek sorry. lol If its open on git I can push you guys 
   a fix for it. If you want.
 * [http://wordpress.org/plugins/bepro-listings/](http://wordpress.org/plugins/bepro-listings/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Thread Starter [carterconnection21](https://wordpress.org/support/users/carterconnection21/)
 * (@carterconnection21)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/google-maps-api-curl-call/#post-4491825)
 * Correction:
 * results is an array
 *  Anonymous User 10273379
 * (@anonymized-10273379)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/google-maps-api-curl-call/#post-4491839)
 * Hello,
 * Thanks for bringing this to our attention. Always happy to hear from fellow geeks
 * Yes, results is an array and as you can see with the section “results[0]” we 
   treat it as an array. Also, before using the variable, we check its object holder“
   $addr_search_1” with the line if($addr_search_1). I’m assuming your assertion,
   is that this object is returning true with an empty array?
 * WP.org seems to have an old version of the plugin on git : [https://github.com/wp-plugins/bepro-listings](https://github.com/wp-plugins/bepro-listings).
   However, we do not manage any git repos for bepro listings. All development has
   been done in house by our team.
 * If your fix is simple like one line e.g. if(!empty($addr_search_1)) then please
   post it here. If its more involved you can either
 * A) Post it on a script posting website and paste the link here
    B) Come over 
   to our [bepro listings forums](https://wordpress.org/support/topic/google-maps-api-curl-call/www.beprosoftware.com/forums/forum/bepro-listings/?output_format=md)
   and share the information there.
 * We have encountered lots of weird issues over time with google. Some are server
   specific while others rectify themselves within minutes to hours. However, we
   are always interested in ideas/options for handling google map related errors
   better.
 * _[ [Signature moderated](http://codex.wordpress.org/Forum_Welcome#Signatures).]_
 *  Thread Starter [carterconnection21](https://wordpress.org/support/users/carterconnection21/)
 * (@carterconnection21)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/google-maps-api-curl-call/#post-4491854)
 * I replaced the curl call with file_get_contents();
    ` /* Replace this $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $addresstofind_1); curl_setopt($ch, CURLOPT_USERAGENT,'
   Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101'); curl_setopt(
   $ch, CURLOPT_CONNECTTIMEOUT,1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $
   addr_search_1 = curl_exec($ch); curl_close($ch);
 * /* With */
    $addr_search_1 = file_get_contents($addresstofind_1);
 * then:
    if(!empty($addr_search_1)){ $addr_search_1 = json_decode($addr_search_1);
 *  if(!empty($addr_search_1->results)){
    if($addr_search_1->results[0]->geometry-
   >location){ $lon = (string)$addr_search_1->results[0]->geometry->location->lng;
   $lat = (string)$addr_search_1->results[0]->geometry->location->lat; } } }
 * it may be a bit much but if that array returns empty and with out a condition
   for that it will error out.
 *  Thread Starter [carterconnection21](https://wordpress.org/support/users/carterconnection21/)
 * (@carterconnection21)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/google-maps-api-curl-call/#post-4491855)
 * The curl call wasn’t bringing the results back even though the url was correct.
   So the simpler thing to do is use file_get_contents().
 *  Anonymous User 10273379
 * (@anonymized-10273379)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/google-maps-api-curl-call/#post-4491859)
 * Hi,
 * Thanks again for your suggestions. Its great to hear that you found a solution
   which works well for you. Bringing issues like this to us, is the only way we
   can improve BePro Listings.
 * Unfortunately, “file_get_contents” requires that certain php features be activated,
   specifically “allow_url_fopen” in the php.ini file. Not every server is setup
   this way and not every user is capable of activating this feature.
 * To support as many users as possible, we opted months ago to use curl. It is 
   definitely surprising that this did not work in your situation. It would have
   been great to learn more about your specific server setup, to ascertain why it
   didn’t work for you. We encourage any users reading this post and experiencing
   the same issue, to utilize our [wordpress development services](http://beprosoftware.com/services)
   to have us investigate. If the plugin really is at fault, we will refund all 
   related purchases.
 * _[ [Signature moderated](http://codex.wordpress.org/Forum_Welcome#Signatures).]_
 *  Thread Starter [carterconnection21](https://wordpress.org/support/users/carterconnection21/)
 * (@carterconnection21)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/google-maps-api-curl-call/#post-4491869)
 * Didn’t know that.
 * Thanks.
 *  [WIBeditor](https://wordpress.org/support/users/wibeditor/)
 * (@wibeditor)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/google-maps-api-curl-call/#post-4491908)
 * I ran into this issue on my local development virtual machine. [@carterconnection21](https://wordpress.org/support/users/carterconnection21/)’
   s approach worked. But CURL works as normal on my staging server, so I assume
   it’ll work in production. Not sure what the problem was with the dev server… 
   but I’m sure other people are likely to run into this issue as well.
 * You might consider patching in this code with an advanced option in plugin settings
   to toggle the “alternate Google Maps geocoding method,” or something like that.
 *  Anonymous User 10273379
 * (@anonymized-10273379)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/google-maps-api-curl-call/#post-4491909)
 * Hi [@wibeditor](https://wordpress.org/support/users/wibeditor/),
 * You and [@carterconnection21](https://wordpress.org/support/users/carterconnection21/)
   make a great point. We are not 100% sure why curl works intermittently. However,“
   file_get_contents” seems to work in those cases.
 * We will implement this feature on the next “BePro Listings” release. Please allow
   24-48 hrs for us to test and release the new admin option.
 * Thanks for reaching out with this information. Comments like this, are the only
   way we can make BePro Listings more robust and dependable!
 * _[ [Signature moderated](http://codex.wordpress.org/Forum_Welcome#Signatures).]_
 *  Anonymous User 10273379
 * (@anonymized-10273379)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/google-maps-api-curl-call/#post-4491911)
 * Hi,
 * As promised, bepro listings 2.0.92 now offers a new option in the admin area,
   allowing you to switch between curl and file_get_contents.
 * Thanks again for your suggestions
 * _[ [Signature moderated](http://codex.wordpress.org/Forum_Welcome#Signatures).]_

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘google maps api curl call’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/bepro-listings.svg)
 * [BePro Listings](https://wordpress.org/plugins/bepro-listings/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/bepro-listings/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/bepro-listings/)
 * [Active Topics](https://wordpress.org/support/plugin/bepro-listings/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/bepro-listings/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/bepro-listings/reviews/)

## Tags

 * [allow_url_fopen()](https://wordpress.org/support/topic-tag/allow_url_fopen/)
 * [api](https://wordpress.org/support/topic-tag/api/)
 * [curl](https://wordpress.org/support/topic-tag/curl/)
 * [error-handling](https://wordpress.org/support/topic-tag/error-handling/)
 * [file_get_contents](https://wordpress.org/support/topic-tag/file_get_contents/)

 * 9 replies
 * 3 participants
 * Last reply from: Anonymous User 10273379
 * Last activity: [12 years, 4 months ago](https://wordpress.org/support/topic/google-maps-api-curl-call/#post-4491911)
 * Status: resolved