Location search: where do the suggestions come from?

Home Forums Calendar Products Events Calendar PRO Location search: where do the suggestions come from?

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1179997
    Richard
    Participant

    We are based in the UK. We are looking forward to using The Events Calendar on the new site I am currently building. There is a facility in The Events Calendar to search by location (the “near location” field).

    If I enter “Birmingham” and click “Find Events” I get a pop-up list asking me to clarify which Birmingham I mean. That would be lovely, but it only offers me a choice of “Birmingham, AL, USA” or “Birmingham, MI, USA” – see screenshot.

    Just to be clear: the Birmingham I want our users to be able to search for is the 2nd city of the United Kingdom, with a population approximately 5 times that of Birmingham, Alabama and 55 times that of Birmingham, Michigan. It is entirely reasonable for a UK-based user (and our membership is predominately in the UK) to want to search for events near Birmingham. Searches for nearby towns such as “Solihull” or “Sutton Coldfield” do return appropriate results.

    Where is this list coming from, and is it editable? Or is there somewhere we can give it a little hint that, in case of doubt, site visitors are probably thinking of the one in the UK? It would be a shame to have to hide the location search, but if it can’t work for such an obvious search then that’s the alternative.

    The same issue occurs on your demo site at http://wpshindig.com/events/ so it doesn’t appear to be a theme issue.

    Thanks!

    #1180196
    Cliff
    Member

    Hi, Richard.

    You’re definitely not the first to report this issue, but it’s not one we’ve figured out yet.

    There isn’t any USA-bias in our code that we’re aware of, but it does seem to be that way…

    The location suggestions pop-ups come from the process_geocoding function in /wp-content/plugins/events-calendar-pro/src/resources/js/tribe-events-pro.js

    Also see the setup_geoloc_in_query() function in /wp-content/plugins/events-calendar-pro/src/Tribe/Geo_Loc.php

    Maybe this information will help you if you decide to dig into some code. Please let me know if you think I can be of further assistance here or if you have any code suggestions for us.

    #1180404
    Richard
    Participant

    OK – you’re using the Google Maps Javascript API’s Geocoder class, and it looks like that’s where the USA bias is coming from.

    Looking at the Google API documentation, there’s an optional parameter “region” which they describe as “Country code used to bias the search, specified as a Unicode region subtag / CLDR identifier.”

    Comparing the returned data from http://maps.googleapis.com/maps/api/geocode/json?address=birmingham and http://maps.googleapis.com/maps/api/geocode/json?address=birmingham&region=uk it looks like that may well be what we need.

    Perhaps it might be possible to add an option in the Events Calendar preferences, allow us to optionally set a region?

    #1180749
    Cliff
    Member

    Richard, this suggestion looks promising.

    I also found

    • /wp-content/plugins/events-calendar-pro/src/resources/js/tribe-events-ajax-maps.js
    • /wp-content/plugins/events-calendar-pro/src/Tribe/Asset/Ajax_Maps.php

    I was hoping to find the line to implement ‘region’, but plunking region: uk in the JS or &region=uk in the PHP didn’t bring me any joy in my testing by temporarily editing the core plugin files.

    If you find a way to implement it, please let me know and I’ll throw some bonus months to your license expiration date. If you don’t, that’s okay too; I’ll just add the information you shared already to our internal bug ticket and hopefully our developers can figure out more details.

    Thanks again for your helpful suggestions!

    #1180800
    Richard
    Participant

    OK, I have this working on the dev site – hooray!

    * Edited wp-config.php to add this line:

    define(‘SCRIPT_DEBUG’, true);

    (That’s so it runs my edited version of the JavaScript, rather than the out-of-the-box minified version.)

    * Edited wp-content/plugins/events-calendar-pro/src/resources/js/tribe-events-pro.js and added line 272, so that the start of process_geocoding now looks like this:

    process_geocoding: function( location, callback ) {

    var request = {
    address: location,
    bounds : new google.maps.LatLngBounds(
    new google.maps.LatLng( TribeEventsPro.geocenter.min_lat, TribeEventsPro.geocenter.min_lng ),
    new google.maps.LatLng( TribeEventsPro.geocenter.max_lat, TribeEventsPro.geocenter.max_lng )
    ),
    region: ‘uk’, // <<<<< Added this line
    };

    // etc.

    And, after reloading the page and making sure I wasn’t using a cached page that had loaded the minified version, it work!

    I’ve not attempted to add a setting to configure the region; your guys will know those parts of your code far better than I do.

    I’m guessing that this setting would ultimately end up being sent to the page in the “TribeEventsPro” object that is part of the inline script generated by enqueue_pro_scripts() in wp-content/plugins/events-calendar-pro/src/Tribe/Main.php

    /**
    * Enqueue the proper PRO scripts as necessary.
    *
    * @return void
    */
    public function enqueue_pro_scripts() {
    if ( tribe_is_event_query() ) {
    // @TODO filter the tribe_events_resource_url() function
    $path = Tribe__Events__Pro__Template_Factory::getMinFile( tribe_events_pro_resource_url( ‘tribe-events-pro.js’ ), true );
    wp_enqueue_script(
    ‘tribe-events-pro’,
    $path,
    array(
    ‘jquery’,
    ‘tribe-events-calendar-script’,
    ),
    apply_filters( ‘tribe_events_pro_js_version’, self::VERSION ),
    false
    );

    $geoloc = Tribe__Events__Pro__Geo_Loc::instance();

    $data = array(
    ‘geocenter’ => $geoloc->estimate_center_point(),
    ‘map_tooltip_event’ => __( ‘Event: ‘, ‘tribe-events-calendar-pro’ ),
    ‘map_tooltip_address’ => __( ‘Address: ‘, ‘tribe-events-calendar-pro’ ),
    ‘region’ => ‘uk’, // <<<<< Added this; it should be retrieved from The Events Calendar Pro settings
    );

    $data = apply_filters( ‘tribe_events_pro_localize_script’, $data, ‘Tribe__Events__Pro__Main’, ‘tribe-events-pro’ );

    wp_localize_script( ‘tribe-events-pro’, ‘TribeEventsPro’, $data );

    }
    }

    and then picked up in tribe-events-pro.js like this:

    process_geocoding: function( location, callback ) {

    var request = {
    address: location,
    bounds : new google.maps.LatLngBounds(
    new google.maps.LatLng( TribeEventsPro.geocenter.min_lat, TribeEventsPro.geocenter.min_lng ),
    new google.maps.LatLng( TribeEventsPro.geocenter.max_lat, TribeEventsPro.geocenter.max_lng )
    ),
    region: TribeEventsPro.region, // <<<<< Added this line
    };

    // etc.

    #1180883
    Cliff
    Member

    Great job!

    I tried the same region: ‘uk’ but forgot define( ‘SCRIPT_DEBUG’, true ); — doh! 😉

    I extended your PRO license from 2017-09-24 to 2017-12-31 and submitted the code suggestions to our internal bug ticket.

    I’d suggest just hard-coding region: ‘uk’ in the core file until we get a fix released for this (don’t forget the minified file if you want to use it on your production site)

    Another idea instead of having a user-input for a preferred region could be to detect the most-used country amongst all the Venues (possibly only of upcoming events).

    Again, good work, thanks for your efforts, and hopefully we’ll get this implemented in a reasonable time!

    #1180895
    Richard
    Participant

    Thanks!

    #1180979
    Mathew
    Participant

    +1

    I’d like to see the region code as a setting in TEC’s admin screen as well an entry place for setting Geo bounds for biasing.

    I’ve used used both methods, depending on client needs. I’ll post to uservoice.

    #1181471
    Cliff
    Member

    Richard and Mathew,

    Thanks for sharing. Mathew, if you do post to UserVoice, please link to it from here.

    #1191890
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

    #1620176
    Victor
    Member

    Hi There!

    Just wanted to share with you that you can set the region and language biasing with the following snippet:

    https://gist.github.com/cliffordp/c7c2713e9f61166e9aef746823be6bfa

    We recommend the following guide for best practices when implementing custom code snippets like this one > https://theeventscalendar.com/knowledgebase/implementing-custom-code-snippets/

    I hope that helps to improve the Near filter functionality for your site. Don’t hesitate to open a new topic if anything comes up.

    Best,
    Victor

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘Location search: where do the suggestions come from?’ is closed to new replies.