Home > Back-end >  Google places autocomplete library
Google places autocomplete library

Time:01-11

I am wanting to restrict the search results of a google places search to just locations in the UK on reading the documentation I have add an attribute the libraries URL,

components=country:gb

I have added this so my script src now looks like,

https://maps.googleapis.com/maps/api/js?key={MY_API_KEY}&libraries=places&components=country:gb&callback=initMap

But i can still return results from outside of the UK, I assume I am doing some wrong with my script src?

CodePudding user response:

Kindly replace gb with uk

https://maps.googleapis.com/maps/api/js?key={MY_API_KEY}&libraries=places&components=country:gb&callback=initMap

CodePudding user response:

Looks like it's a param of the service not the request URL, so I had to do,

return this.service.getPlacePredictions({
    input: searchValue,
    componentRestrictions: { country: 'gb'}
}, this.displayResults.bind(this));
  •  Tags:  
  • Related