Location autocomplete behaviour/reuse
This topic contains 6 replies, has 3 voices, and was last updated by Stiofan O’Connor 6 years, 4 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support TicketTagged: address, autocomplete, google, location, search
-
AuthorPosts
-
June 19, 2018 at 12:22 pm #435482
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
AlexJune 19, 2018 at 1:33 pm #4355051. 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.
June 20, 2018 at 1:05 pm #435651Thanks 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
AlexJune 20, 2018 at 1:09 pm #435652Actually, 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.
June 20, 2018 at 1:35 pm #435666You could write in such a way that it can be placed in functions.php, but then instead place it as a code snippet:
June 20, 2018 at 1:40 pm #435667I 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
AlexJune 20, 2018 at 3:57 pm #435697I would rather help you “fix” how OZ works than help you make all your listings incompatible with future versions of GD 🙂
Stiofan
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket