Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 views
in Technique[技术] by (71.8m points)

ruby on rails - Google Maps API - Autocomplete Suggestions are missing some locations/places

We're using Google Maps' API in our Rails application, with a VueJS frontend.

I don't think any of the above is important because I've checked the URL JSON response in the browser and it's missing locations. It seems to work ok for city names, postcodes - but it's not showing the same suggestions as when I type into a location field in Google Calendar for example.

Request URL (with obvious tokens/auth keys removed):-

https://maps.googleapis.com/maps/api/place/autocomplete/json?types=geocode&input=Ritz%20London

Response:-

{
   "predictions" : [
      {
         "description" : "Ritz Parade, London, UK",
         "matched_substrings" : [
            {
               "length" : 4,
               "offset" : 0
            },
            {
               "length" : 6,
               "offset" : 13
            }
         ],
         "place_id" : "EhdSaXR6IFBhcmFkZSwgTG9uZG9uLCBVSyIuKiwKFAoSCbu6Pcob",
         "reference" : "EhdSaXR6IFBhcmFkZSwgTG9uZG9uLCBVSyIuKiwKFAoSCbu6PcobEnZIEbPVf1MZfE",
         "structured_formatting" : {
            "main_text" : "Ritz Parade",
            "main_text_matched_substrings" : [
               {
                  "length" : 4,
                  "offset" : 0
               }
            ],
            "secondary_text" : "London, UK",
            "secondary_text_matched_substrings" : [
               {
                  "length" : 6,
                  "offset" : 0
               }
            ]
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "Ritz Parade"
            },
            {
               "offset" : 13,
               "value" : "London"
            },
            {
               "offset" : 21,
               "value" : "UK"
            }
         ],
         "types" : [ "route", "geocode" ]
      }
   ],
   "status" : "OK"
}

The actual Ritz Hotel in London isn't shown here, yet it's clearly showing in my Google Calendar location search.

I don't currently have access to our API Console but imagine this is a setting that either needs to be turned on in the API Console, or passed as an additional param in our request? Or am I looking in the wrong place?

question from:https://stackoverflow.com/questions/66046682/google-maps-api-autocomplete-suggestions-are-missing-some-locations-places

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Doing the same search and using establishment as the types parameter returns the result you are probably after.

According to the types documentation:

establishment instructs the Place Autocomplete service to return only business results.

Request with types=establishment: https://maps.googleapis.com/maps/api/place/autocomplete/json?types=establishment&input=Ritz%20London&language=en&key=your_api_key_here

{
   "predictions" : [
      {
         "description" : "The Ritz London, Piccadilly, London, UK",
         "matched_substrings" : [
            {
               "length" : 4,
               "offset" : 4
            },
            {
               "length" : 6,
               "offset" : 29
            }
         ],
         "place_id" : "ChIJV8gP0ykFdkgRFEAEHoE1YVk",
         "reference" : "ChIJV8gP0ykFdkgRFEAEHoE1YVk",
         "structured_formatting" : {
            "main_text" : "The Ritz London",
            "main_text_matched_substrings" : [
               {
                  "length" : 4,
                  "offset" : 4
               }
            ],
            "secondary_text" : "Piccadilly, London, UK",
            "secondary_text_matched_substrings" : [
               {
                  "length" : 6,
                  "offset" : 12
               }
            ]
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "The Ritz London"
            },
            {
               "offset" : 17,
               "value" : "Piccadilly"
            },
            {
               "offset" : 29,
               "value" : "London"
            },
            {
               "offset" : 37,
               "value" : "UK"
            }
         ],
         "types" : [ "lodging", "restaurant", "food", "point_of_interest", "establishment" ]
      },
      {
         "description" : "Ritz, London, UK",
         "matched_substrings" : [
            {
               "length" : 4,
               "offset" : 0
            },
            {
               "length" : 6,
               "offset" : 6
            }
         ],
         "place_id" : "ChIJ1wd5z6gFdkgRUdbMn3pMiKM",
         "reference" : "ChIJ1wd5z6gFdkgRUdbMn3pMiKM",
         "structured_formatting" : {
            "main_text" : "Ritz",
            "main_text_matched_substrings" : [
               {
                  "length" : 4,
                  "offset" : 0
               }
            ],
            "secondary_text" : "London, UK",
            "secondary_text_matched_substrings" : [
               {
                  "length" : 6,
                  "offset" : 0
               }
            ]
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "Ritz"
            },
            {
               "offset" : 6,
               "value" : "London"
            },
            {
               "offset" : 14,
               "value" : "UK"
            }
         ],
         "types" : [ "laundry", "point_of_interest", "establishment" ]
      },
      {
         "description" : "Ritz London Cigars, Piccadilly, London, UK",
         "matched_substrings" : [
            {
               "length" : 11,
               "offset" : 0
            }
         ],
         "place_id" : "ChIJa_Ih9V8FdkgRfNt8eaSIXuw",
         "reference" : "ChIJa_Ih9V8FdkgRfNt8eaSIXuw",
         "structured_formatting" : {
            "main_text" : "Ritz London Cigars",
            "main_text_matched_substrings" : [
               {
                  "length" : 11,
                  "offset" : 0
               }
            ],
            "secondary_text" : "Piccadilly, London, UK"
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "Ritz London Cigars"
            },
            {
               "offset" : 20,
               "value" : "Piccadilly"
            },
            {
               "offset" : 32,
               "value" : "London"
            },
            {
               "offset" : 40,
               "value" : "UK"
            }
         ],
         "types" : [ "point_of_interest", "store", "establishment" ]
      },
      {
         "description" : "Hiro Miyoshi at The Ritz London, The Ritz, Piccadilly, London, UK",
         "matched_substrings" : [
            {
               "length" : 11,
               "offset" : 20
            }
         ],
         "place_id" : "ChIJcXuw6tkFdkgR89PgYYTudzU",
         "reference" : "ChIJcXuw6tkFdkgR89PgYYTudzU",
         "structured_formatting" : {
            "main_text" : "Hiro Miyoshi at The Ritz London",
            "main_text_matched_substrings" : [
               {
                  "length" : 11,
                  "offset" : 20
               }
            ],
            "secondary_text" : "The Ritz, Piccadilly, London, UK"
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "Hiro Miyoshi at The Ritz London"
            },
            {
               "offset" : 33,
               "value" : "The Ritz"
            },
            {
               "offset" : 43,
               "value" : "Piccadilly"
            },
            {
               "offset" : 55,
               "value" : "London"
            },
            {
               "offset" : 63,
               "value" : "UK"
            }
         ],
         "types" : [
            "beauty_salon",
            "hair_care",
            "spa",
            "point_of_interest",
            "store",
            "establishment"
         ]
      },
      {
         "description" : "Ritz Restaurant, King Street, London, UK",
         "matched_substrings" : [
            {
               "length" : 4,
               "offset" : 0
            },
            {
               "length" : 6,
               "offset" : 30
            }
         ],
         "place_id" : "ChIJOVU94EkOdkgRqhr357HTODs",
         "reference" : "ChIJOVU94EkOdkgRqhr357HTODs",
         "structured_formatting" : {
            "main_text" : "Ritz Restaurant",
            "main_text_matched_substrings" : [
               {
                  "length" : 4,
                  "offset" : 0
               }
            ],
            "secondary_text" : "King Street, London, UK",
            "secondary_text_matched_substrings" : [
               {
                  "length" : 6,
                  "offset" : 13
               }
            ]
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "Ritz Restaurant"
            },
            {
               "offset" : 17,
               "value" : "King Street"
            },
            {
               "offset" : 30,
               "value" : "London"
            },
            {
               "offset" : 38,
               "value" : "UK"
            }
         ],
         "types" : [
            "cafe",
            "restaurant",
            "food",
            "point_of_interest",
            "store",
            "establishment"
         ]
      }
   ],
   "status" : "OK"
}

On the same documentation page:

If nothing is specified, all types are returned. In general only a single type is allowed. The exception is that you can safely mix the geocode and establishment types, but note that this will have the same effect as specifying no types.

Request with no specified types: https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Ritz%20London&language=en&key=your_api_key_here

{
   "predictions" : [
      {
         "description" : "The Ritz London, Piccadilly, London, UK",
         "matched_substrings" : [
            {
               "length" : 4,
               "offset" : 4
            },
            {
               "length" : 6,
               "offset" : 29
            }
         ],
         "place_id" : "ChIJV8gP0ykFdkgRFEAEHoE1YVk",
         "reference" : "ChIJV8gP0ykFdkgRFEAEHoE1YVk",
         "structured_formatting" : {
            "main_text" : "The Ritz London",
            "main_text_matched_substrings" : [
               {
                  "length" : 4,
                  "offset" : 4
               }
            ],
            "secondary_text" : "Piccadilly, London, UK",
            "secondary_text_matched_substrings" : [
               {
                  "length" : 6,
                  "offset" : 12
               }
            ]
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "The Ritz London"
            },
            {
               "offset" : 17,
               "value" : "Piccadilly"
            },
            {
               "offset" : 29,
               "value" : "London"
            },
            {
             

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...