Google Places REST API指定类型过滤无效问题咨询
Hey there, let's work through why your Places API request isn't returning the restaurant results you expect. First off, there's a clear formatting mistake in your request URL that's throwing off the API's ability to parse your filters:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=lat,long&radius=50&type=restaurantkeyword=restaurant&key=MY_API_KEY
The Core Issue: Malformed Parameter Separation
You've merged two parameters (type=restaurant and keyword=restaurant) together without the required & separator. Also, & is an HTML-escaped version of &—when building a raw request URL, you should use plain & to split parameters. Here's the corrected, functional URL:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=lat,long&radius=50&type=restaurant&keyword=restaurant&key=MY_API_KEY
Additional Troubleshooting Steps
- Validate Your Coordinates: Double-check that
lat,longis a precise, valid location. A 50-meter radius is extremely small—there might simply be no restaurants in that tiny area! Try expanding the radius to 200-500 meters for testing. - Simplify the Request: Temporarily remove the
keyword=restaurantparameter and test with justtype=restaurant. Combiningtypeandkeywordcan sometimes over-filter results, especially in limited geographic ranges. - Check API Key Permissions: Confirm your API key has the Places API enabled in the Google Cloud Console. Also, make sure you haven't hit your usage quota or been restricted from accessing the service.
- Inspect API Responses: If you get an error like
INVALID_REQUEST, read the error message closely—it will explicitly tell you what's wrong. If you get empty results, that’s a sign there are no matching restaurants in your specified radius and location.
内容的提问来源于stack exchange,提问作者Gastón Saillán

