代码之家  ›  专栏  ›  技术社区  ›  onesiumus

使用Google Places Insights API搜索酒吧时,如何排除与食物相关的次要类型?

  •  1
  • onesiumus  · 技术社区  · 5 月前

    我正在尝试使用新的Places Insights API来统计我所在城市的酒吧,但我得到了意想不到的结果。我想统计一下主要是酒吧的地方,而不是碰巧有酒吧的餐馆。我当前的查询如下:

    {
        "insights": ["INSIGHT_COUNT"],
        "filter": {
            "locationFilter": {
                "region": {
                    "place": "places/ChIJIQBpAG2ahYAR_6128GcTUEo"
                }
            },
            "typeFilter": {
                "includedTypes": ["bar"]
            }
        }
    }
    

    这会返回太多的结果,因为它包括将“酒吧”作为次要类型的餐厅。我如何修改我的查询,只获取主要是酒吧的地方?

    1 回复  |  直到 5 月前
        1
  •  1
  •   Parth Patel    5 月前

    要只找到主要是酒吧的地方(不是有酒吧的餐馆),你应该使用 includedPrimaryTypes 而不是 includedTypes 。原因如下:

    1. 包含类型 匹配主要和次要类型,因此它将返回任何在任一类别中都有“bar”的位置
    2. 包括主要类型 仅与主类型匹配,因此它将仅返回“bar”为主分类的位置

    以下是更正后的查询:

    json
    {
        "insights": ["INSIGHT_COUNT"],
        "filter": {
            "locationFilter": {
                "region": {
                    "place": "places/ChIJIQBpAG2ahYAR_6128GcTUEo"
                }
            },
            "typeFilter": {
                "includedPrimaryTypes": ["bar"]
            }
        }
    }
    

    为了更精确地过滤,您可以明确排除餐馆:

    json
    {
        "insights": ["INSIGHT_COUNT"],
        "filter": {
            "locationFilter": {
                "region": {
                    "place": "places/ChIJIQBpAG2ahYAR_6128GcTUEo"
                }
            },
            "typeFilter": {
                "includedPrimaryTypes": ["bar"],
                "excludedTypes": ["restaurant"]
            }
        }
    }