5

I've been able to make requests to the Places API from Google Maps, but I always get one result.

For example, searching something like "The White House", or an actual street address, get one single result:

https://maps.googleapis.com/maps/api/place/findplacefromtext/json
  ?input=the%20white%20house
  &inputtype=textquery
  &fields=formatted_address,name,geometry
  &key=API_KEY

response: {
  candidates: [
    {
      formatted_address: "1600 Pennsylvania Ave NW, Washington, DC 20500, USA",
      geometry: {
        location: {
          lat: 38.8976763,
          lng: -77.0365298
        },
        viewport: {
          northeast: {
            lat: 38.90148105,
            lng: -77.03520012010728
          },
          southwest: {
            lat: 38.89640805000001,
            lng: -77.03789977989273
          }
        }
      },
      name: "The White House"
    }
  ],
  status: "OK"
};

What if I want to find, to be cliche, all the Starbucks around me? (how to limit the search radius is a later question)

https://maps.googleapis.com/maps/api/place/findplacefromtext/json
  ?input=starbucks
  &inputtype=textquery
  &fields=formatted_address,name,geometry
  &key=API_KEY

response: {
  candidates: [],
  status: "ZERO_RESULTS"
};

Some comments indicate that I should be getting a different response for my "Starbucks" search. Why aren't I?

Jonathan Tuzman
  • 11,568
  • 18
  • 69
  • 129
  • 1
    The geocoder expects an address as an input, and will in most cases only return the single closest match. Not sure how you are testing the Places API, but I usually get 20 results for "starbucks" (using `SearchBox`). Please provide a [mcve] that demonstrates your issue. – geocodezip Mar 29 '19 at 17:01
  • Related question: [google maps javascript api v3 places library deosn't return any results for the bounds](https://stackoverflow.com/questions/12613127/google-maps-javascript-api-v3-places-library-deosnt-return-any-results-for-the) – geocodezip Mar 29 '19 at 20:34

1 Answers1

0

You can try Nearby Search. Just please note that there is no way to constrain Nearby Search requests to only return specific fields.

Just look at the sample request below:

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=38.8976763%2C-77.0365298&radius=50000&keyword=mcdonalds&key=YOUR_KEY

The response will give you all McDonalds store in this specific location 38.8976763,-77.0365298. You will also notice that there's a radius parameter of 50000 to return the place results.

rafon
  • 1,469
  • 11
  • 21