最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to exclude food-related secondary types when searching for bars using Google Places Insights API? - Stack Overflow

programmeradmin2浏览0评论

I'm trying to use the new Places Insights API to count bars in my city, but I'm getting unexpected results. I want to count places that are primarily bars but NOT restaurants that happen to have a bar. My current query looks like this:

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

This returns way too many results because it's including restaurants that have "bar" as a secondary type. How can I modify my query to only get places that are primarily bars?

I'm trying to use the new Places Insights API to count bars in my city, but I'm getting unexpected results. I want to count places that are primarily bars but NOT restaurants that happen to have a bar. My current query looks like this:

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

This returns way too many results because it's including restaurants that have "bar" as a secondary type. How can I modify my query to only get places that are primarily bars?

Share Improve this question edited yesterday miguev 4,85523 silver badges42 bronze badges asked Feb 7 at 23:49 onesiumusonesiumus 3318 silver badges28 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

To get only places that are primarily bars (not restaurants with bars), you should use includedPrimaryTypes instead of includedTypes. Here's why:

  1. includedTypes matches against both primary and secondary types, so it will return any place that has "bar" in either category
  2. includedPrimaryTypes only matches against the primary type, so it will return only places where "bar" is the main classification

Here's the corrected query:

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

For even more precise filtering, you could explicitly exclude restaurants:

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论