fairground
fairground

Reputation: 61

Google API URL type search returns unexpected results

I'm using Google Maps API Nearby Search to find restaurants in an area. But one problem I've been having is that not all results of type=restaurant are returned. In the case of a particular point in Wellesley, MA, when I run https://maps.googleapis.com/maps/api/place/nearbysearch/xml?location=42.3153566,-71.2449400&radius=1500&type=restaurant&key=MY_API_KEY, I am able to get three results, including Brothers Pizza in Needham, Panellas Market in Needham Heights, and Kings Dining in Wellesley, all with the type of restaurant. However, when I change the type=restaurant to keyword=wok, I get only one result that I hadn't gotten before:

<name>The Wok</name>
<vicinity>180 Worcester St, Wellesley</vicinity>
<type>restaurant</type>
<type>food</type>
<type>point_of_interest</type>
<type>establishment</type>
<geometry>
    <location>
        <lat>42.3153566</lat>
        <lng>-71.2449400</lng>
...

This is obviously tagged as a restaurant, just like the other three. Note that the coordinates for The Wok are exactly the ones I used for the earlier query which did not return The Wok, so it's definitely within the radius of the earlier query which should have also returned this fourth result. This is causing an issue for me, as I want to be able to collect all of the restaurants in a given area. It seems then that the Google API does not collect all results from within an area, but rather some mysterious fraction of them. I am already aware that one search does not produce more than twenty results, but my previous search, starting from a radius centered at The Wok, produced only three results. I've been able to replicate this particular problem with The Wok several times, so might it be an issue with the data Google has specifically for The Wok?

EDIT: Usingkeyword=restaurantsolves the issue, but since the API searches many fields, including reviews, to find potential matches for the keyword, this might provide unwanted results. I'm looking strictly for restaurants, not other kinds of establishments.

Upvotes: 2

Views: 234

Answers (1)

geocodezip
geocodezip

Reputation: 161384

NearbySearch defaults torankby=prominence, you probably want rankby=distance. However that won't let you specify the radius (and still doesn't seem to return "The Wok".

Optional parameters

rankby — Specifies the order in which results are listed. Note that rankby must not be included if radius (described under Required parameters above) is specified. Possible values are:

  • prominence (default). This option sorts results based on their importance. Ranking will favor prominent places within the specified area. Prominence can be affected by a place's ranking in Google's index, global popularity, and other factors.
  • distance. This option biases search results in ascending order by their distance from the specified location. When distance is specified, one or more of keyword, name, or type is required.

Upvotes: 1

Related Questions