title: Filter Google Places autocomplete results by country
body: <p>I’m working on an Android app in which I want the user to search for data (that my app is providing) in a specific city. For that I have a search field in which the user can type in a city name. I use the Google Places API to retrieve autocomplete results like this:</p>
  
  <p><pre><code>
      PendingResult results =  Places.GeoDataApi .getAutocompletePredictions(mGoogleApiClient, searchQuery,  mBounds, mPlaceFilter);</pre></code></p>
  
  <p>In my case mBounds represents the bounds of Germany, because I’m only interested in cities in Germany and I don’t want cities in other countries to show up in the autocomplete predictions. Now, obviously Germany isn’t a perfect square, so mBounds contains the whole of Germany, but also parts of surrounding countries like Switzerland. So the questions is: How can I remove all autocomplete predictions for places that are <strong>not</strong> in Germany?</p>
  
  <p>My first thought was to use a place filter to only get predictions for one country in the first place. According to the <a href="https://developers.google.com/places/supported_types">documentation</a> this can indeed be used to filter by regions (e.g. by countries), but unfortunately this specific filtering is <strong>not supported in Google Places API for Android</strong> (according to the documentation).</p>
  
  <blockquote>
    <p>The (regions) type collection is not supported in Google Places API for Android.</p>
  </blockquote>
  
  <p>There also doesn’t seem to be any possibility to get the country of a <a href="https://developers.google.com/android/reference/com/google/android/gms/location/places/Place%20Place">Place</a> from either the <a href="https://developers.google.com/android/reference/com/google/android/gms/location/places/AutocompletePrediction">AutocompletePrediction</a> or the <a href="https://developers.google.com/android/reference/com/google/android/gms/location/places/Place%20Place">Place</a> object. So I can’t even do the filtering myself.</p>
  
  <p>The only solutions I can think of are the following:</p>
  
  <ol>
  <li><p>Get the <a href="https://developers.google.com/android/reference/com/google/android/gms/location/places/Place%20Place">Place</a> from the prediction and use the <a href="http://developer.android.com/intl/zh-CN/reference/android/location/Geocoder.html">Geocoder API</a> to retrieve the <a href="http://developer.android.com/intl/zh-CN/reference/android/location/Address.html">Address</a> and from that get the country and do the filtering. However, that’s an additional network call (and another one against my quota) that seems totally unnecessary as it seems to me that the <a href="https://developers.google.com/android/reference/com/google/android/gms/location/places/AutocompletePrediction">AutocompletePrediction</a> object or at least the <a href="https://developers.google.com/android/reference/com/google/android/gms/location/places/Place%20Place">Place</a> objects should know in which country a place is. After all, it’s part of the description / toString results of those objects. However, that’s just a string like “Munich, Germany”.</p></li>
  <li><p>Use the description string mentioned in 1. to determine the country. However that seems like an even worse solution than 1, since the description is localized depending on the user’s locale which could be everything. So just looking for “Germany” wouldn’t do the job.</p></li>
  </ol>
  
  <p>I would appreciate a solution that’s better than what I have proposed so far. I can’t imagine that there isn’t a better way to do this. Any ideas?</p>