googlemaps / google-maps-services-js

Node.js client library for Google Maps API Web Services
Apache License 2.0
2.86k stars 631 forks source link

Places.placeAutocomplete can't filter by country #1199

Closed usuarez closed 2 months ago

usuarez commented 2 months ago

Environment

API: Places placeAutocomplete OS: Ubuntu Node: 18.13.0

Steps to reproduce

  1. Config the client
  2. Call the placeAutocomplete method
  3. Set the components param

Code example

Client.placeAutocomplete({
      params: {
        key: this.key,
        input: suggestion,
        language: Language.es,
        components: ["country:ve','country:es"],
        strictbounds: true,
      },
    }).then((data) => data.data);

Stack trace

as the package suggest components param is A grouping of places to which you would like to restrict your results. Currently, you can use components to filter by up to 5 countries. Countries must be passed as a two character, ISO 3166-1 Alpha-2 compatible country code. For example: components=country:fr would restrict your results to places within France. Multiple countries must be passed as multiple country:XX filters, with the pipe character (|) as a separator. For example: components=country:us|country:pr|country:vi|country:gu|country:mp would restrict your results to places within the United States and its unincorporated organized territories.

calling the api in postman works perfectly https://maps.googleapis.com/maps/api/place/autocomplete/json?input=hotel venezuela&key=key&components=country:ve

but with this package the components param is an string[] and i test with:

components: ["ve","es"]
components: ["country:ve","country:es"]
components: ["country:ve|country:es"]
components: ["components=country:us"]
components: ["components=country:us|country:pr"]

None of these works properly cuz i get results from other countries too and using the strictbounds: true kill my server

{
    "predictions": [
        {
            "description": "Hotel Venezuela - Rua Paissandu - Flamengo, Rio de Janeiro - State of Rio de Janeiro, Brazil",
            "matched_substrings": [
                {
                    "length": 15,
                    "offset": 0
                }
            ],
            "place_id": "ChIJO-_SfYd_mQARcd-6E2docfw",
            "reference": "ChIJO-_SfYd_mQARcd-6E2docfw",
            "structured_formatting": {
                "main_text": "Hotel Venezuela",
                "main_text_matched_substrings": [
                    {
                        "length": 15,
                        "offset": 0
                    }
                ],
                "secondary_text": "Rua Paissandu - Flamengo, Rio de Janeiro - State of Rio de Janeiro, Brazil"
            },
            "terms": [
                {
                    "offset": 0,
                    "value": "Hotel Venezuela"
                },
                {
                    "offset": 18,
                    "value": "Rua Paissandu"
                },
                {
                    "offset": 34,
                    "value": "Flamengo"
                },
                {
                    "offset": 44,
                    "value": "Rio de Janeiro"
                },
                {
                    "offset": 61,
                    "value": "State of Rio de Janeiro"
                },
                {
                    "offset": 86,
                    "value": "Brazil"
                }
            ],
            "types": [
                "lodging",
                "point_of_interest",
                "establishment"
            ]
        },
        {
            "description": "Hotel Venezuela, Via dello Storione, Lido, Metropolitan City of Venice, Italy",
            "matched_substrings": [
                {
                    "length": 15,
                    "offset": 0
                }
            ],
            "place_id": "ChIJD6c1z58AfEcR6yDgXgI4ykk",
            "reference": "ChIJD6c1z58AfEcR6yDgXgI4ykk",
            "structured_formatting": {
                "main_text": "Hotel Venezuela",
                "main_text_matched_substrings": [
                    {
                        "length": 15,
                        "offset": 0
                    }
                ],
                "secondary_text": "Via dello Storione, Lido, Metropolitan City of Venice, Italy"
            },
            "terms": [
                {
                    "offset": 0,
                    "value": "Hotel Venezuela"
                },
                {
                    "offset": 17,
                    "value": "Via dello Storione"
                },
                {
                    "offset": 37,
                    "value": "Lido"
                },
                {
                    "offset": 43,
                    "value": "Metropolitan City of Venice"
                },
                {
                    "offset": 72,
                    "value": "Italy"
                }
            ],
            "types": [
                "lodging",
                "point_of_interest",
                "establishment"
            ]
        },
        {
            "description": "Hotel Venezuela, Venezuela, ABG, Buenos Aires, Argentina",
            "matched_substrings": [
                {
                    "length": 15,
                    "offset": 0
                }
            ],
            "place_id": "ChIJGTGg9t3KvJUR6aqCqzUKS4I",
            "reference": "ChIJGTGg9t3KvJUR6aqCqzUKS4I",
            "structured_formatting": {
                "main_text": "Hotel Venezuela",
                "main_text_matched_substrings": [
                    {
                        "length": 15,
                        "offset": 0
                    }
                ],
                "secondary_text": "Venezuela, ABG, Buenos Aires, Argentina"
            },
            "terms": [
                {
                    "offset": 0,
                    "value": "Hotel Venezuela"
                },
                {
                    "offset": 17,
                    "value": "Venezuela"
                },
                {
                    "offset": 28,
                    "value": "ABG"
                },
                {
                    "offset": 33,
                    "value": "Buenos Aires"
                },
                {
                    "offset": 47,
                    "value": "Argentina"
                }
            ],
            "types": [
                "lodging",
                "point_of_interest",
                "establishment"
            ]
        },
        {
            "description": "Hotel Venezuela, Plaza Suso Gayoso, Vilalba, Spain",
            "matched_substrings": [
                {
                    "length": 15,
                    "offset": 0
                }
            ],
            "place_id": "ChIJkQeE_KPmMQ0RGJbTSpO6x-c",
            "reference": "ChIJkQeE_KPmMQ0RGJbTSpO6x-c",
            "structured_formatting": {
                "main_text": "Hotel Venezuela",
                "main_text_matched_substrings": [
                    {
                        "length": 15,
                        "offset": 0
                    }
                ],
                "secondary_text": "Plaza Suso Gayoso, Vilalba, Spain"
            },
            "terms": [
                {
                    "offset": 0,
                    "value": "Hotel Venezuela"
                },
                {
                    "offset": 17,
                    "value": "Plaza Suso Gayoso"
                },
                {
                    "offset": 36,
                    "value": "Vilalba"
                },
                {
                    "offset": 45,
                    "value": "Spain"
                }
            ],
            "types": [
                "lodging",
                "point_of_interest",
                "establishment"
            ]
        },
        {
            "description": "Hotel Venezuela - Albergo, Via Cesare Battisti, Montesano Scalo, SA, Italy",
            "matched_substrings": [
                {
                    "length": 15,
                    "offset": 0
                }
            ],
            "place_id": "ChIJb5wTKCQsORMRavUiuRUvsX8",
            "reference": "ChIJb5wTKCQsORMRavUiuRUvsX8",
            "structured_formatting": {
                "main_text": "Hotel Venezuela - Albergo",
                "main_text_matched_substrings": [
                    {
                        "length": 15,
                        "offset": 0
                    }
                ],
                "secondary_text": "Via Cesare Battisti, Montesano Scalo, SA, Italy"
            },
            "terms": [
                {
                    "offset": 0,
                    "value": "Hotel Venezuela - Albergo"
                },
                {
                    "offset": 27,
                    "value": "Via Cesare Battisti"
                },
                {
                    "offset": 48,
                    "value": "Montesano Scalo"
                },
                {
                    "offset": 65,
                    "value": "SA"
                },
                {
                    "offset": 69,
                    "value": "Italy"
                }
            ],
            "types": [
                "restaurant",
                "lodging",
                "point_of_interest",
                "food",
                "establishment"
            ]
        }
    ],
    "status": "OK"
}
wangela commented 2 months ago

If you would like to upvote the priority of this issue, please comment below or react on the original post above with :+1: so we can see what is popular when we triage.

@usuarez Thank you for opening this issue. 🙏 Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.