Restrict search results in google places api by particular area or state in a country, react native (Javascript)

Viewed 194

I am using Google Places API in my react native app and I want to filter or restrict search results.

I want to restrict the search results to the Mumbai region or a particular state (only Kerala). How can I do it?

code I used in my project.

 const url = 'https://maps.googleapis.com/maps/api/place/textsearch/json?query=' 
  + Address +'&key=' + YOUR_API_KEY +'&types=(point_of_interest,establishment)&language=en&country=IN'

  fetch(url)
    .then(res => {
      return res.json()
    })
    .then(res => {
      if(res.results.length > 0){
        setLocationResults(res.results)
      }else{
        setLocationResults([])
      }
    })
    .catch(error => {
      console.log("ERR :",error);
    });
1 Answers

One way you can achieve this as Google's Places API does not understand such segregations is to pass the location and radius params. You just set the location to the center of the state/region and then set a sufficient radius which will cover the whole region.

You can check out the docs here

Related