Google Place API type过滤异常:指定establishment却返回其他类型地点
type=establishment in Google Places Nearby Search? Let's break down the issue and fix it step by step:
Possible Causes
- Missing required
locationparameter: Your request has an emptylocation=value, which is a critical required field for Nearby Search. This API needs a precise latitude/longitude coordinate to define the center of your search area. Without it, the API can't properly filter results to your desiredestablishmenttype, leading to unexpected results like routes, localities, or political areas. - Broad scope of
establishmenttype: Theestablishmenttype is a broad category covering almost all commercial venues. Some valid results might have additional type tags (likelocalityif the business sits in a specific neighborhood), but if the primary type of the result is non-establishment, the missinglocationis almost certainly the culprit.
Fixes to Try
Add a valid
locationcoordinate
You must provide a valid lat/lng pair to define your search center. For example, if you're searching in São Paulo, your request would look like this:https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-23.550520,-46.633308&radius=40&type=establishment&language=pt_BR&key=YOUR_API_KEYThis ensures the API only searches for establishments within the 40-meter radius around your specified point.
Use more specific types instead of
establishment
If you need tighter results, replaceestablishmentwith a more granular type likerestaurant,loja(store in Portuguese),cafe, orsupermarket. These narrower types will reduce irrelevant matches significantly.Filter with the
keywordparameter
Combine your type with a keyword to refine results further. For example, addingkeyword="comércio"(commerce in Portuguese) will help prioritize commercial venues even more:https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-23.550520,-46.633308&radius=40&type=establishment&keyword=comércio&language=pt_BR&key=YOUR_API_KEYVerify result types in the response
When you get results, check thetypesarray in each item. Valid establishment results will haveestablishmentas one of the top types, even if they include other tags likelocality. If the primary type is non-establishment, double-check yourlocationparameter is correctly formatted.
内容的提问来源于stack exchange,提问作者Hudson Pereira




