Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass query options through geocoded_by? #1118

Closed
toppa opened this issue Nov 18, 2016 · 5 comments
Closed

Pass query options through geocoded_by? #1118

toppa opened this issue Nov 18, 2016 · 5 comments
Assignees
Labels

Comments

@toppa
Copy link

toppa commented Nov 18, 2016

I'm trying to figure out if it's possible to pass query options with geocoded_by - I don't see this mentioned in the docs. Specifically, I want to pass arguments to the Googe API's components parameter. I can do it with Geocoder.search, but I don't see how to do it with my method that's invoked by geocoded_by - it seems to want only a single string returned, and if I correctly understand its option for passing a block, it's for handling results. Is it possible to do this?

@TrangPham
Copy link
Contributor

Hi @toppa

There are a few things that you could pass to geocoded_by. You can see those options here:

def geocoded_by(address_attr, options = {}, &block)
geocoder_init(
:geocode => true,
:user_address => address_attr,
:latitude => options[:latitude] || :latitude,
:longitude => options[:longitude] || :longitude,
:geocode_block => block,
:units => options[:units],
:method => options[:method],
:lookup => options[:lookup],
:language => options[:language]
)

But currently no way to handle passing params. We are open to accepting a pull request for this feature as this question has been asked before by others: #765

Currently this can be achieved only by writing custom geocode method. See the linked issue for example.

Thanks!

@toppa
Copy link
Author

toppa commented Nov 18, 2016

Thanks for the quick reply. It looks like we would need to open this up to allow for user supplied params. This is my first time looking at the Geocoder internals, so I'm not sure offhand how options[:user_address] gets populated from the :geocoded_by method. But my thought is to maybe add support for something like :geocoded_by_params which would populate a new options[:user_params], which we could add to that query_options hash. Does that general idea make sense?

@TrangPham
Copy link
Contributor

@toppa That is correct. options[:user_params] should be adding into the query_options

Instead of :geocoded_by_params, I would suggest just calling it :params to match the style of the search function. This would also be nicer on reverse_geocoded_by. So that calling would look like:

geocoded_by :address, :params => {region: 'US'}

reverse_geocoded_by :lat, :lon, :params => {region: 'US'}

Here is where the :user_address is coming from:

:user_address => address_attr,

I didn't 100% get how it gets from there to the do_lookup function itself. It's getting the geocoder_options from the class that's calling into do_lookup I believe - but then geocoder_options is actually defined in the model base class not the store base class:

def geocoder_options
.
And do_lookup is called from the store classes:
do_lookup(false) do |o,rs|

So there's a step I'm missing here. Maybe @alexreisner could explain more?

Thanks so much for wanting to add this feature! Please ensure to add some unit tests!

@TrangPham TrangPham self-assigned this Jun 1, 2017
@TrangPham
Copy link
Contributor

I think I will try to implement this 😶

@alexreisner
Copy link
Owner

Added by #1188.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants