add state & country to geolocation search form
5 posts by 3 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: June 1, 2015 (RSS)
By Toledoh - May 31, 2015
Hi all,
I am using the basic proximity search form for the geolocation plugin. Is there any way that I can add "Queensland, Australia" to any search entered? I want to make sure that if someone types "Texas", that the search is for Texas Queensland Australia - rather than working off Texas USA.
<form method="post" action="?" class="form-inline" role="form" id="proximitySearch">
<input type="hidden" name="search" value="1" />
<div class="form-group">
<label class="sr-only" for="fromAddress">Town name or postcode</label>
<input type="text" name="fromAddress" value="<?php echo htmlspecialchars(@$_REQUEST['fromAddress']); ?>" class="form-control" />
<input type="hidden" name="maxDistance" value="" />
</div><button type="submit" class="btn btn-default">Search</button>
</form>
Tim (toledoh.com.au)
By Damon - June 1, 2015
Hi Tim,
In the sample_search.php form, one of the example included with the Geocoder, you will find this code on 12:
if (!array_key_exists('fromAddress', $_REQUEST)) { $_REQUEST['fromAddress'] = '10001'; } // this is the default address/postalcode if none entered
change to this:
if (!array_key_exists('fromAddress', $_REQUEST)) { $_REQUEST['fromAddress'] = ' Queensland Australia'; } // this is the default address/postalcode if none entered
This will add "Queensland Australia" by default and then the user can add the city.
Also, to get more accurate region specific results, uncomment and set the region on line 20 in the geocoder.php file:
// Google's Geocoding API typically does a good job of guessing what region you
// want results from when there are ambiguities in the search. If necessary, you
// can supply this optional "region" parameter to influence the choices made.
// See: http://code.google.com/apis/maps/documentation/geocoding/#RegionCodes
$GLOBALS['GEOCODER_REGION'] = 'au'; // two-letter ccTLD, eg: us, uk, ref: http://code.google.com/apis/maps/documentation/javascript/basics.html#Region
Hope this helps!
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
By Toledoh - June 1, 2015
Hi Damon,
I think that 'fromAddress' will be replaced if people type in the field? I need the Queensland Australia added to whatever they put in.
I was thinking that there would be some kind of "append" kind of thing.
The GEOCODER_REGION only identifies the country. If someone types "brighton" - the system doesn't know whether it's Brighton in Victoria, New South Wales, or Queensland. For this website, it is purely focussed on Queensland, so I want to make the search "brighton" plus Queensland, Australia.
Tim (toledoh.com.au)
By Dave - June 1, 2015
Hi Tim,
How about this?
if (@$_REQUEST['fromAddress']) { $_REQUEST['fromAddress'] .= ", Queensland, Australia"; }
Let me know if that works for you.
interactivetools.com