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

Places: Allow multiple country:XX in component param #128

Closed
denkan opened this issue Nov 4, 2017 · 10 comments
Closed

Places: Allow multiple country:XX in component param #128

denkan opened this issue Nov 4, 2017 · 10 comments

Comments

@denkan
Copy link

denkan commented Nov 4, 2017

According to the docs, we're suppose to be able to filter search results to up to 5 countries by adding multiple piped country:xx, as components=country:us|country:pr|country:vi|country:gu|country:mp.

However, this is not possible when current param type is an object, as component:{country:'us'}.

I've tried different ways with string, arrays etc with no luck.

Suggestion:
Accept object OR string as component param.

@v1adko
Copy link

v1adko commented Nov 27, 2017

I agree, this would be very useful. Also would like to know if there's a way to sort suggestions or assign priority? Or an open feature request where we can vote on?

In my use case it would be useful to have suggestions first grouped/filtered by a certain country and only then list suggestions for all countries (without the country limitation) as there is this open issue.

@jer-sen
Copy link

jer-sen commented Mar 1, 2018

Note that the current documentation is wrong. It's written that components must be Array.<string> but in fact it has to be an object like { country: 'us }.

Cf https://googlemaps.github.io/google-maps-services-js/docs/GoogleMapsClient.html

@zaarheed
Copy link

I am able to filter by one country only in v0.4.6 like so:

{
    input: <input>,
    components: {
        country: ["gb"]
    }
}

Filtering by multiple countries as mentioned in the docs would be great but not essential for me right now. I may pull-request a fix if I get some time...

@dunika
Copy link

dunika commented Jul 28, 2018

Okay after digging into the code there seems to be a bug with how it is building the query. According to the docs the string produced needs to be in the form country:code|country:code but when you pass multiple country codes as an array it produces country: code, code.

I was able to get multiple countries working with the following

components: { country: ['gb|country:ie'] },

Which produces the query

 components: 'country:gb|country:ie'

@ghost
Copy link

ghost commented Sep 21, 2018

I switched the pipedKeyValues for this:

exports.pipedKeyValues = function(arg) {
  if (!arg || typeof arg !== 'object') {
    throw new v.InvalidValueError('not an Object');
  }
  const pipedKeys = [];
  for (const key of Object.keys(arg)) {
    for (let k = 0; k < arg[key].length; k += 1) {
      pipedKeys.push(`${key}:${arg[key][k]}`)
    }
  }
  return pipedKeys.join('|')
};

And it worked. It's not very efficient but it's okay. I also haven't tested to see if it screws with anything else.

@stephenmcd
Copy link
Contributor

This is resolved in #192

@ghost
Copy link

ghost commented Oct 22, 2018

Is this on the road map to be published to the npm package: @google/maps ?

1 similar comment
@ghost
Copy link

ghost commented Oct 22, 2018

Is this on the road map to be published to the npm package: @google/maps ?

@eveevans
Copy link

Okay after digging into the code there seems to be a bug with how it is building the query. According to the docs the string produced needs to be in the form country:code|country:code but when you pass multiple country codes as an array it produces country: code, code.

I was able to get multiple countries working with the following

components: { country: ['gb|country:ie'] },

Which produces the query

 components: 'country:gb|country:ie'

This is wrong.
Component Filtering documentations says that this filter should works as an "AND" not as an "OR", so in your case, this filter by gb and ie , not gb or ie

https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering

@dunika
Copy link

dunika commented Jul 1, 2020

@eveevans Ye, I know it's an AND query. My comment was more a means of getting it to work

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

No branches or pull requests

7 participants