Location autocomplete behaviour/reuse

This topic contains 6 replies, has 3 voices, and was last updated by  Stiofan O’Connor 6 years, 3 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #435482

    Alexander Crichton
    Free User
    Post count: 6

    Hi

    Couple of questions regarding the location autocomplete

    1. I understand that GD needs to file listings under region/city. However, maybe due to how Australia treats suburbs, I’ve found it best to hide all notions of region/city in my site and just show a single complete address, e.g. 100 Newnham Rd, Mount Gravatt East, QLD.

    It’s almost working great. When adding a listing, you can type “100 Newnham” into the address field and get the suggestion “100 Newnham Rd, Mount Gravatt East, QLD”, but when you select a suggestion it splits the address across the region and city fields. I plan to hide the region/city fields from the user, and I’ve no problem with GD extracting that information to use internally, but can it insert the full suggested value into the address field, rather than just the street segment?

    I’m aware this isn’t possible through the plugin settings (would love to be proven wrong). Is it in any way possible through JS or something? I haven’t delved into the source yet to see what event handlers I might be able to override (just guessing). I was hoping someone might already have an answer, or might have done something similar.

    2. Is it possible to get the location autocomplete suggestions in the search boxes? I don’t see any settings for that either. Once again, happy to attempt some JS. If it’s already being applied to the address field, maybe it can be applied to the search boxes.

    Thanks
    Alex

    #435505

    Alex Rollin
    Moderator
    Post count: 27815

    1. Automatically store complete address in address field

    Currently no setting, correct.

    2. Google Address autocomplete in Search field

    Google autocomplete doesn’t work in the NEAR field as you discovered, see also http://wpgeodirectory.com/docs/gd-search

    I will flag your question about this customization for the developers.

    #435651

    Alexander Crichton
    Free User
    Post count: 6

    Thanks Alex

    I actually found a solution to question 1. Seems to be working so far. I found where the address is set from the autocomplete callback.

    In

    plugins/geodir_location_manager/geodir_location_hooks_actions.php

    it outputs the JS function

    fillInAddress

    which does

    jQuery('#<?php echo $prefix . 'address'; ?>').val(place.name);

    .

    I changed it to

    jQuery('#<?php echo $prefix . 'address'; ?>').val(place.formatted_address);

    which is the whole suggested value e.g. ‘579 Kessels Rd, MacGregor QLD 4109’

    I’m not too familiar with WordPress, but I understand directly modifying plugin files isn’t a good long-term solution. Is there any way for me to persist that change somewhere else that won’t be overwritten when the plugin updates?

    Still working on question 2.

    Thanks
    Alex

    #435652

    Alexander Crichton
    Free User
    Post count: 6

    Actually, I just noticed that

    fillInAddress

    is called as a global variable. I guess it’d be easy enough to add my own script through the plugin that overwrites that function with my modified version. I guess I’ll have to keep an eye on whether that function is changed in any plugin updates.

    #435666

    Alex Rollin
    Moderator
    Post count: 27815

    You could write in such a way that it can be placed in functions.php, but then instead place it as a code snippet:

    https://wpgeodirectory.com/docs/useful-plugins/#snippets

    #435667

    Alexander Crichton
    Free User
    Post count: 6

    I tried this as a footer script in Geodirectory > Design > Scripts

    
    
    
    <script type="text/javascript">
        function replaceFillInAddress() {
            if (fillInAddress == null) {
                setTimeout(replaceFillInAddress, 200);
                return;
            }
    
            fillInAddress = function () {
                fillInAddress();
    
                var place = autocomplete.getPlace();
    
                if (place.formatted_address) {
                    jQuery('#post_address').val(place.formatted_address);
                }
            };
        }
    
        replaceFillInAddress();
    </script>
    

    It has to retry because it’s included before the plugin scripts. Anyway, it looked like it was working, but the map wouldn’t change position when selecting a suggestion. Clicking ‘Set Address On Map’ would do it, but it’s nicer when you don’t have to do that.

    I guess this approach is slightly less fragile. Any idea why the map doesn’t auto update with this approach?

    Thanks
    Alex

    #435697

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    I would rather help you “fix” how OZ works than help you make all your listings incompatible with future versions of GD 🙂

    Stiofan

Viewing 7 posts - 1 through 7 (of 7 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount