BP Distance Search bug

BP Profile Search BP Distance Search bug

  • Author
    Post
  • #12361 Reply
    Golax
    Guest

    Hi Andrea,

    Thanks for the fascinating plugins.

    I’m using BP Distance Search with BP Profile Search and I ran into a strange problem. On the profile registration the autorecommendation works perfectly and the search is fine clicking on it’s result, as well.

    But if I add a Location field in BP Profile Search the autocoplete doesn’t show up and the search is faulty, as well.

    I have this error in the console:

    jquery.min.js?ver=3.7.1:2 Uncaught ReferenceError: google is not defined
    at bps_autocomplete (bps-template.js?ver=5.7.4:13:21)
    at HTMLDocument.<anonymous> (search-members/:520:26)
    at e (jquery.min.js?ver=3.7.1:2:27028)
    at t (jquery.min.js?ver=3.7.1:2:27330)

    Could you help me with this?

    Thanks

    #12362 Reply
    andrea
    Plugin Author

    Hi Golax,

    Thank you for your report!

    Could you please paste here the BP Profile Search site information? See:

    https://dontdream.it/bp-profile-search-5-4-6/

    for details.

    #12364 Reply
    Golax
    Guest

    Hi,

    Thanks for getting back to me.

    Platform BuddyPress 12.5.0, BP Classic
    Theme Gwangi Child 1.2
    Members index template /plugins/grimlock-buddypress/templates/members/index.php
    Members loop template /plugins/grimlock-buddypress/templates/members/members-loop.php
    Form template(s) /plugins/grimlock-buddypress/templates/members/bps-form-directory.php
    /plugins/grimlock-buddypress/templates/members/bps-form-home.php

    #12365 Reply
    andrea
    Plugin Author

    Hi Golax,

    Thanks for your info.

    Could you please check if you have other errors in your console, related to Google Maps JavaScript API?

    #12366 Reply
    Golax
    Guest

    I see now. I had this error:

    jquery.min.js?ver=3.7.1:2 jQuery.Deferred exception: google is not defined ReferenceError: google is not defined
        at bps_autocomplete (https://laszloa20.sg-host.com/wp-content/plugins/bp-profile-search/bps-template.js?ver=5.7.4:13:21)
        at HTMLDocument.<anonymous> (https://laszloa20.sg-host.com/search-members/:777:26)
        at e (https://laszloa20.sg-host.com/wp-includes/js/jquery/jquery.min.js?ver=3.7.1:2:27028)
        at t (https://laszloa20.sg-host.com/wp-includes/js/jquery/jquery.min.js?ver=3.7.1:2:27330) undefined
    ce.Deferred.exceptionHook @ jquery.min.js?ver=3.7.1:2
    jquery.min.js?ver=3.7.1:2 Uncaught ReferenceError: google is not defined
        at bps_autocomplete (bps-template.js?ver=5.7.4:13:21)
        at HTMLDocument.<anonymous> (search-members/:777:26)
        at e (jquery.min.js?ver=3.7.1:2:27028)
        at t (jquery.min.js?ver=3.7.1:2:27330)

    I added this snippet to my functions.php and it works now fine:

     function load_google_maps_api() {
        if (is_page('search-members')) { // Only load on specific page if needed
            wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=herewasmyapikey&libraries=places', array(), null, true);
        }
    }
    add_action('wp_enqueue_scripts', 'load_google_maps_api');

    The google object was being referenced without being loaded first.

    I don’t understand half of what I wrote, ChatGPT is a hell of a tool 😀

    #12368 Reply
    andrea
    Plugin Author

    That’s great!

    Actually BP Distance Search should be able to load the Google API by itself, if you entered your API key when creating your Location field, but your code is a good solution anyway.

Reply to: BP Distance Search bug
My Information