-1

I am using google.maps.places.AutocompleteService(); to get query predictions. Is it possible to omit country name from the predictions list of users location. For eaxmple. if i am in united states, when i search for sanfransisco. It should not show United states (Country name) in predictions list. But if i search for location- delhi in india, it should show 'Delhi India'(country name).

Is this possible using this service or any other google api service.

Note that, i need list of suggestion, not something tied with a textfield. Your help will be greatly appreciated.

Paulson Peter
  • 574
  • 4
  • 12

1 Answers1

1

This is not possible without manually processing the results. So after receiving the json data as a response, you need to check if the suggested country is the same as the user's country and if it is then do not display it in the textfield.

A JSON response looks like this: In the value field you can check the country and decide whether or not to display it by comparing it to the user's country that needs to be set somewhere in your App.

I believe the JSON response will be save in a List<HashMap<String, String>> So you can loop over it and omit the country.

{
  "status": "OK",
  "predictions" : [
      {
         "description" : "Paris, France",
         "id" : "691b237b0322f28988f3ce03e321ff72a12167fd",
         "matched_substrings" : [
            {
               "length" : 5,
               "offset" : 0
            }
         ],
         "place_id" : "ChIJD7fiBh9u5kcRYJSMaMOCCwQ",
         "reference" : "CjQlAAAA_KB6EEceSTfkteSSF6U0pvumHCoLUboRcDlAH05N1pZJLmOQbYmboEi0SwXBSoI2EhAhj249tFDCVh4R-PXZkPK8GhTBmp_6_lWljaf1joVs1SH2ttB_tw",
         "terms" : [
            {
               "offset" : 0,
               "value" : "Paris"
            },
            {
               "offset" : 7,
               "value" : "France"
            }
         ],
         "types" : [ "locality", "political", "geocode" ]
      },
      {
         "description" : "Paris Avenue, Earlwood, New South Wales, Australia",
         "id" : "359a75f8beff14b1c94f3d42c2aabfac2afbabad",
         "matched_substrings" : [
            {
               "length" : 5,
               "offset" : 0
            }
         ],
         "place_id" : "ChIJrU3KAHG6EmsR5Uwfrk7azrI",
         "reference" : "CkQ2AAAARbzLE-tsSQPgwv8JKBaVtbjY48kInQo9tny0k07FOYb3Z_z_yDTFhQB_Ehpu-IKhvj8Msdb1rJlX7xMr9kfOVRIQVuL4tOtx9L7U8pC0Zx5bLBoUTFbw9R2lTn_EuBayhDvugt8T0Oo",
         "terms" : [
            {
               "offset" : 0,
               "value" : "Paris Avenue"
            },
            {
               "offset" : 14,
               "value" : "Earlwood"
            },
            {
               "offset" : 24,
               "value" : "New South Wales"
            },
            {
               "offset" : 41,
               "value" : "Australia"
            }
         ],

...

Reference: https://developers.google.com/places/webservice/autocomplete#location_biasing

Ziad Halabi
  • 964
  • 11
  • 31