You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Google Place API type过滤异常:指定establishment却返回其他类型地点

Let's break down the issue and fix it step by step:

Possible Causes

  • Missing required location parameter: Your request has an empty location= 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 desired establishment type, leading to unexpected results like routes, localities, or political areas.
  • Broad scope of establishment type: The establishment type is a broad category covering almost all commercial venues. Some valid results might have additional type tags (like locality if the business sits in a specific neighborhood), but if the primary type of the result is non-establishment, the missing location is almost certainly the culprit.

Fixes to Try

  1. Add a valid location coordinate
    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_KEY
    

    This ensures the API only searches for establishments within the 40-meter radius around your specified point.

  2. Use more specific types instead of establishment
    If you need tighter results, replace establishment with a more granular type like restaurant, loja (store in Portuguese), cafe, or supermarket. These narrower types will reduce irrelevant matches significantly.

  3. Filter with the keyword parameter
    Combine your type with a keyword to refine results further. For example, adding keyword="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_KEY
    
  4. Verify result types in the response
    When you get results, check the types array in each item. Valid establishment results will have establishment as one of the top types, even if they include other tags like locality. If the primary type is non-establishment, double-check your location parameter is correctly formatted.

内容的提问来源于stack exchange,提问作者Hudson Pereira

火山引擎 最新活动