Search code examples
androidgoogle-mapsgoogle-places

Google Places consuming from REST not filtering by desired type


I'm consuming a result from the REST API of Google Places, so far this is what Google Maps tell me about the nearest places around me

enter image description here

Now, I'm using this URL to query my results

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=lat,long&radius=50&type=restaurantkeyword=restaurant&key=MY_API_KEY

According to this, I'm using the correct type = to filter my query.

I'm filtering by type restaurant with a radios of 50 meters; now, the result that the rest provides to me is this:

enter image description here

Where you can see that the results showing here are not for the type restaurant, but instead it searches for all establishments as the FAQ says

Why are some places not returned when I filter by type? It's possible that the place you are looking for has not yet been categorized. All places are categorized as the generic type "establishment" until Google has enough data about a place to categorize it as one of the supported place types.

As a workaround you can pass the place type to the keyword parameter. The keyword parameter is matched to: name, type, address, and customer reviews.

If you would like to add the category type to a place listing yourself, submit a place edit. Once the edit has been approved and published it will appear using the correct type filtering.

But the problem is that indeed in Google Maps it appears to be restaurants near me, but the query just return all the establishments around me.

Is there a way to fix that response in order to just return the restaurants near me and not all the places?


Solution

  • Your url query has bug. You need to insert an '&' between restaurant and keyword. I tested with the below query and it looks correct:

    https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-31.41668,-64.1909&radius=50&type=restaurant&keyword=restaurant&key=MY_API_KEY