Alexander Crichton

Forum Replies Created

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • in reply to: Location autocomplete behaviour/reuse #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

    in reply to: Location autocomplete behaviour/reuse #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.

    in reply to: Location autocomplete behaviour/reuse #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

Viewing 3 posts - 1 through 3 (of 3 total)
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount