Skip to content

Instantly share code, notes, and snippets.

@DavidSpriggs
Last active December 24, 2015 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidSpriggs/6867772 to your computer and use it in GitHub Desktop.
Save DavidSpriggs/6867772 to your computer and use it in GitHub Desktop.
Geocoder suggest filtering.
The suggest service does not honor the sourceCountry parameter. This function works to filter results based on a regEx.
In post create:
this.own(aspect.before(this.geocoder, '_hydrateResults', lang.hitch(this, 'scrubGeocodeAutoComplete')));
member function:
scrubGeocodeAutoComplete: function(results) {
var re = /United States/i;
var scrubedResults = [];
array.forEach(results, function(result) {
if (result.text && result.text.match(re)) {
scrubedResults.push(result);
} else if (result.name && result.name.match(re)) {
scrubedResults.push(result);
}
});
return [scrubedResults];
}
@dkoppMTM
Copy link

Hey Dave,
Although I couldn't find it documented anywhere, it appears that as of 3.10, the geocoder isn't returning "name" any longer, it instead returns "address". Changing the above to reference result.address instead of result.name corrected our app.

Just thought I'd share in case you still use this function.

Thanks,
Dennis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment