WordPress.org

Ready to get started?Download WordPress

Forums

BePro Listings
[resolved] google maps api curl call (10 posts)

  1. carterconnection21
    Member
    Posted 7 months ago #

    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/

  2. carterconnection21
    Member
    Posted 7 months ago #

    Correction:

    results is an array

  3. BeyondPrograms
    Member
    Plugin Author

    Posted 7 months ago #

    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. 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 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. ]

  4. carterconnection21
    Member
    Posted 7 months ago #

    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.

  5. carterconnection21
    Member
    Posted 7 months ago #

    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().

  6. BeyondPrograms
    Member
    Plugin Author

    Posted 7 months ago #

    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 to have us investigate. If the plugin really is at fault, we will refund all related purchases.

    [ Signature moderated. ]

  7. carterconnection21
    Member
    Posted 7 months ago #

    Didn't know that.

    Thanks.

  8. WIBeditor
    Member
    Posted 7 months ago #

    I ran into this issue on my local development virtual machine. @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.

  9. BeyondPrograms
    Member
    Plugin Author

    Posted 7 months ago #

    Hi @WIBeditor,

    You and @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. ]

  10. BeyondPrograms
    Member
    Plugin Author

    Posted 7 months ago #

    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. ]

Reply

You must log in to post.

About this Plugin

About this Topic