ฟังก์ชัน PLACES_COUNT
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ฟังก์ชัน PLACES_COUNT
จะแสดงผลค่าการนับเดียวของสถานที่ตามพื้นที่ค้นหาและตัวกรองการค้นหาที่ระบุ คุณต้องระบุพื้นที่ค้นหาให้กับฟังก์ชัน PLACES_COUNT
และระบุพารามิเตอร์ตัวกรองเพิ่มเติมได้โดยไม่บังคับ เช่น ประเภทสถานที่ สถานะการดำเนินงาน ระดับราคา และอื่นๆ
เนื่องจากฟังก์ชัน PLACES_COUNT
แสดงผลค่าเดียว ให้เรียกใช้ฟังก์ชันโดยใช้
คําสั่ง SELECT
พารามิเตอร์อินพุต
ต้องระบุ: geography
พารามิเตอร์ตัวกรองที่
ระบุพื้นที่ค้นหา พารามิเตอร์ geography
จะใช้ค่าที่กำหนด
โดย BigQuery
GEOGRAPHY
ประเภทข้อมูล ซึ่งรองรับจุด เส้น และรูปหลายเหลี่ยม
ไม่บังคับ: พารามิเตอร์ตัวกรองเพิ่มเติมเพื่อปรับแต่งการค้นหา
ค่าที่ส่งคืน:
- ค่า
count
เดียวเป็น INT64
ตัวอย่าง: คำนวณจำนวนสถานที่ในรัศมีการค้นหา
การเรียกฟังก์ชัน PLACES_COUNT
ที่ง่ายที่สุดจะแสดงผลจำนวนสถานที่ทั้งหมด
ในพื้นที่ทางภูมิศาสตร์ ในตัวอย่างนี้ คุณจะแสดงผลจำนวนสถานที่ที่เปิดให้บริการทั้งหมด
ภายในรัศมี 1, 000 เมตรจากตึกเอ็มไพร์สเตต
ตัวอย่างนี้ใช้ฟังก์ชัน BigQuery
ST_GEOGPOINT
เพื่อแสดงค่า GEOGRAPHY
จากจุด
SELECT `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(
JSON_OBJECT(
'geography', ST_GEOGPOINT(-73.9857, 40.7484), -- Empire State Building
'geography_radius', 1000 -- Radius in meters
)
) as count;
การตอบกลับจะมีจำนวนเดียวดังนี้

การเรียกที่พบบ่อยกว่าจะใช้ตัวกรองกับพื้นที่ค้นหา ตัวอย่างถัดไปใช้
ตัวกรองเพื่อจำกัดการค้นหาให้แสดงเฉพาะจำนวนต่อไปนี้
- สถานที่ประเภท
restaurant
ที่มีคะแนนขั้นต่ำ 3
- มีระดับราคาที่ไม่แพงหรือปานกลาง
- ใช้งานได้ในปัจจุบัน
- นำสุนัขเข้าได้
SELECT `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(
JSON_OBJECT(
'geography', ST_GEOGPOINT(-73.9857, 40.7484), -- Empire State Building
'geography_radius', 1000, -- Radius in meters
'types', ["restaurant"],
'min_rating', 3,
'price_level', ['PRICE_LEVEL_INEXPENSIVE', 'PRICE_LEVEL_MODERATE'],
'business_status', ['OPERATIONAL'],
'allows_dogs', TRUE
)
) as count;
คำตอบที่กรองแล้ว

โปรดทราบว่าการค้นหาชุดข้อมูลสถานที่บังคับใช้เกณฑ์จำนวนขั้นต่ำที่
5 ข้อดีอย่างหนึ่งของฟังก์ชันการนับสถานที่คือ
ฟังก์ชันนี้จะแสดงผลการนับใดก็ได้ รวมถึง 0 ตัวอย่างเช่น การเรียกใช้ต่อไปนี้
จะแสดงผลการนับเป็น 1
SELECT `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(
JSON_OBJECT(
'geography', ST_GEOGPOINT(-73.9857, 40.7484), -- Empire State Building
'geography_radius', 500, -- Radius in meters
'types', ["restaurant"],
'min_rating', 4.0,
'free_parking_lot', TRUE,
'good_for_watching_sports', TRUE
)
) as count;
ตัวอย่าง: คำนวณจำนวนร้านอาหารโดยใช้รูปหลายเหลี่ยม
คุณใช้รูปหลายเหลี่ยมเพื่อระบุพื้นที่ค้นหาได้ เมื่อใช้รูปหลายเหลี่ยม
จุดของรูปหลายเหลี่ยมต้องกำหนดลูปปิดโดยที่จุดแรกใน
รูปหลายเหลี่ยมต้องเหมือนกับจุดสุดท้าย
ตัวอย่างนี้ใช้ฟังก์ชัน BigQuery
ST_GEOGFROMTEXT
เพื่อแสดงผลค่า GEOGRAPHY
จากรูปหลายเหลี่ยม
DECLARE geo GEOGRAPHY;
SET geo = ST_GEOGFROMTEXT('''POLYGON((-73.985708 40.75773,-73.993324 40.750298,
-73.9857 40.7484,-73.9785 40.7575,
-73.985708 40.75773))'''); -- NYC viewport
SELECT `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(
JSON_OBJECT(
'geography',geo, -- viewport
'types', ["restaurant"],
'min_rating', 1.0,
'max_rating', 4.5,
'min_user_rating_count', 1,
'max_user_rating_count', 10000,
'price_level', ['PRICE_LEVEL_INEXPENSIVE', 'PRICE_LEVEL_MODERATE'],
'business_status', ['OPERATIONAL'],
'allows_dogs', TRUE
)
) as count;
การตอบสนองสำหรับวิวพอร์ต

ตัวอย่าง: คำนวณจำนวนร้านอาหารโดยใช้เส้น
ในตัวอย่างถัดไป คุณจะกำหนดพื้นที่ค้นหาโดยใช้เส้นของจุดที่เชื่อมต่อกัน
โดยมีรัศมีการค้นหา 100 เมตรรอบเส้น
เส้นทางนี้คล้ายกับเส้นทางการเดินทางที่คำนวณโดย Routes
API เส้นทางอาจเป็นเส้นทางสำหรับยานพาหนะ จักรยาน
หรือคนเดินเท้า
DECLARE geo GEOGRAPHY;
SET geo = ST_GEOGFROMTEXT('LINESTRING(-73.98903537033028 40.73655649223003,-73.93580216278471 40.80955538843361)'); -- NYC line
SELECT `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(
JSON_OBJECT(
'geography',geo, -- line
'geography_radius', 100, -- Radius around line
'types', ["restaurant"],
'min_rating', 1.0,
'max_rating', 4.5,
'min_user_rating_count', 1,
'max_user_rating_count', 10000,
'price_level', ['PRICE_LEVEL_INEXPENSIVE', 'PRICE_LEVEL_MODERATE'],
'business_status', ['OPERATIONAL'],
'allows_dogs', TRUE
)
) as count;
การตอบกลับสำหรับบรรทัด

ตัวอย่าง: รวมผลลัพธ์ของการเรียกหลายครั้ง
คุณรวมผลลัพธ์ของการเรียกใช้หลายครั้งเข้ากับฟังก์ชัน PLACES_COUNT
ได้
เช่น คุณต้องการผลการค้นหาเดียวที่แสดงจำนวนร้านอาหารสำหรับระดับราคาต่อไปนี้ภายในพื้นที่ที่เฉพาะเจาะจง
PRICE_LEVEL_INEXPENSIVE
PRICE_LEVEL_MODERATE
PRICE_LEVEL_EXPENSIVE
PRICE_LEVEL_VERY_EXPENSIVE"
ในตัวอย่างนี้ คุณจะสร้างลูปเพื่อเรียกใช้ฟังก์ชัน PLACES_COUNT
สำหรับแต่ละ
ระดับราคา และแทรกผลลัพธ์ของการเรียกใช้แต่ละครั้งลงในตารางชั่วคราว จากนั้นคุณจะ
ค้นหาตารางชั่วคราวเพื่อแสดงผลลัพธ์ได้โดยใช้คำสั่งต่อไปนี้
-- Create a temp table to hold the results.
CREATE TEMP TABLE results (type STRING, count INT64);
-- Create a loop that calls PLACES_COUNT for each price level.
FOR types IN (SELECT type FROM UNNEST(["PRICE_LEVEL_INEXPENSIVE", "PRICE_LEVEL_MODERATE", "PRICE_LEVEL_EXPENSIVE", "PRICE_LEVEL_VERY_EXPENSIVE"]) as type)
DO
INSERT INTO results VALUES (types.type, `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(
JSON_OBJECT(
'types', ["restaurant"],
'geography', ST_GEOGPOINT(-73.9857, 40.7484), -- Empire State Building
'geography_radius', 1000, -- Radius in meters
'business_status', ['OPERATIONAL'],
'price_level', [types.type]
)));
END FOR;
-- Query the table of results.
SELECT * FROM results;
คำตอบที่รวมกัน

อีกตัวเลือกหนึ่งคือการใช้คำสั่ง UNION ALL
เพื่อรวมผลลัพธ์ของคำสั่ง SELECT
หลายรายการ ตัวอย่างต่อไปนี้แสดงผลลัพธ์เดียวกันกับ
ตัวอย่างก่อนหน้า
SELECT "PRICE_LEVEL_INEXPENSIVE" as price_level, `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(
JSON_OBJECT(
'types', ["restaurant"],
'geography', ST_GEOGPOINT(-73.9857, 40.7484), -- Empire State Building
'geography_radius', 1000, -- Radius in meters
'business_status', ['OPERATIONAL'],
'price_level', ['PRICE_LEVEL_INEXPENSIVE']
)
) as count
UNION ALL
SELECT "PRICE_LEVEL_MODERATE" as price_level, `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(
JSON_OBJECT(
'types', ["restaurant"],
'geography', ST_GEOGPOINT(-73.9857, 40.7484), -- Empire State Building
'geography_radius', 1000, -- Radius in meters
'business_status', ['OPERATIONAL'],
'price_level', ['PRICE_LEVEL_MODERATE']
)
) as count
UNION ALL
SELECT "PRICE_LEVEL_EXPENSIVE" as price_level, `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(
JSON_OBJECT(
'types', ["restaurant"],
'geography', ST_GEOGPOINT(-73.9857, 40.7484), -- Empire State Building
'geography_radius', 1000, -- Radius in meters
'business_status', ['OPERATIONAL'],
'price_level', ['PRICE_LEVEL_EXPENSIVE']
)
) as count
UNION ALL
SELECT "PRICE_LEVEL_VERY_EXPENSIVE" as price_level, `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(
JSON_OBJECT(
'types', ["restaurant"],
'geography', ST_GEOGPOINT(-73.9857, 40.7484), -- Empire State Building
'geography_radius', 1000, -- Radius in meters
'business_status', ['OPERATIONAL'],
'price_level', ['PRICE_LEVEL_VERY_EXPENSIVE']
)
) as count
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-17 UTC
[null,null,["อัปเดตล่าสุด 2025-07-17 UTC"],[],[],null,["The `PLACES_COUNT` function returns a single count value of places based on the\nspecified search area and search filters. You must specify the search area to\nthe `PLACES_COUNT` function and can optionally specify additional filter\nparameters, such as place type, operating status, price level, and more.\n\nBecause the `PLACES_COUNT` function returns a single value, call it using\na `SELECT` clause.\n\n- Input parameters:\n\n - **Required** : The `geography` [filter parameter](/maps/documentation/placesinsights/experimental/filter-params) that\n specifies the search area. The `geography` parameter takes a value defined\n by the BigQuery\n [`GEOGRAPHY`](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#geography_type)\n data type, which supports points, linestrings, and polygons.\n\n - **Optional** : Additional [filter](/maps/documentation/placesinsights/experimental/filter-params) parameters to refine your\n search.\n\n- Returns:\n\n - A single `count` value as an `INT64`.\n\nExample: Calculate the number of places in a search radius\n\nThe simplest `PLACES_COUNT` function call returns a single count of all places\nin a geographical area. In this example, you return the count of all operational\nplaces within 1000 meters of the Empire State building.\n\nThis example uses the BigQuery\n[`ST_GEOGPOINT`](https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions#st_geogpoint)\nfunction to return a `GEOGRAPHY` value from a point. \n\n```googlesql\nSELECT `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(\n JSON_OBJECT(\n 'geography', ST_GEOGPOINT(-73.9857, 40.7484), -- Empire State Building\n 'geography_radius', 1000 -- Radius in meters\n )\n) as count;\n```\n\nThe response contains a single count:\n\nA more typical call applies filters to the search area. The next example uses\nfilters to limit the search to only return a count of:\n\n- Places of type `restaurant` with the minimum rating of 3\n- A price level of inexpensive or medium\n- Currently operational\n- Allows dogs\n\n```googlesql\nSELECT `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(\n JSON_OBJECT(\n 'geography', ST_GEOGPOINT(-73.9857, 40.7484), -- Empire State Building\n 'geography_radius', 1000, -- Radius in meters\n 'types', [\"restaurant\"],\n 'min_rating', 3,\n 'price_level', ['PRICE_LEVEL_INEXPENSIVE', 'PRICE_LEVEL_MODERATE'],\n 'business_status', ['OPERATIONAL'],\n 'allows_dogs', TRUE\n )\n) as count;\n```\n\nThe filtered response:\n\nRemember that place dataset queries enforce a minimum count threshold of\n5. One of the advantages of the place count functions is\nthat they can return any counts, including 0. For example, the following call\nreturns a count of 1: \n\n```googlesql\nSELECT `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(\n JSON_OBJECT(\n 'geography', ST_GEOGPOINT(-73.9857, 40.7484), -- Empire State Building\n 'geography_radius', 500, -- Radius in meters\n 'types', [\"restaurant\"],\n 'min_rating', 4.0,\n 'free_parking_lot', TRUE,\n 'good_for_watching_sports', TRUE\n )\n) as count;\n```\n\nExample: Calculate the number of restaurants using a polygon\n\nYou can use a polygon to specify the search area. When using a polygon,\nthe points of the polygon must define a closed loop where the first point in the\npolygon is the same as the last point.\n\nThis example uses the BigQuery\n[`ST_GEOGFROMTEXT`](https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions#st_geogfromtext)\nfunction to return a `GEOGRAPHY` value from a polygon. \n\n```googlesql\nDECLARE geo GEOGRAPHY;\nSET geo = ST_GEOGFROMTEXT('''POLYGON((-73.985708 40.75773,-73.993324 40.750298,\n -73.9857 40.7484,-73.9785 40.7575,\n -73.985708 40.75773))'''); -- NYC viewport\n\nSELECT `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(\n JSON_OBJECT(\n 'geography',geo, -- viewport \n 'types', [\"restaurant\"],\n 'min_rating', 1.0,\n 'max_rating', 4.5,\n 'min_user_rating_count', 1,\n 'max_user_rating_count', 10000,\n 'price_level', ['PRICE_LEVEL_INEXPENSIVE', 'PRICE_LEVEL_MODERATE'],\n 'business_status', ['OPERATIONAL'],\n 'allows_dogs', TRUE\n )\n) as count;\n```\n\nThe response for the viewport:\n\nExample: Calculate the number of restaurants using a line\n\nIn the next example, you define the search area using a line of connected\npoints with a search radius of 100 meters around the line.\nThe line is similar to a travel route calculated by the [Routes\nAPI](/maps/documentation/routes). The route might be for a vehicle, a bicycle,\nor for a pedestrian: \n\n```googlesql\nDECLARE geo GEOGRAPHY;\nSET geo = ST_GEOGFROMTEXT('LINESTRING(-73.98903537033028 40.73655649223003,-73.93580216278471 40.80955538843361)'); -- NYC line\n\nSELECT `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(\n JSON_OBJECT(\n 'geography',geo, -- line\n 'geography_radius', 100, -- Radius around line\n 'types', [\"restaurant\"],\n 'min_rating', 1.0,\n 'max_rating', 4.5,\n 'min_user_rating_count', 1,\n 'max_user_rating_count', 10000,\n 'price_level', ['PRICE_LEVEL_INEXPENSIVE', 'PRICE_LEVEL_MODERATE'],\n 'business_status', ['OPERATIONAL'],\n 'allows_dogs', TRUE\n )\n) as count;\n```\n\nThe response for the line:\n\nExample: Combine the results of multiple calls\n\nYou can combine the results of multiple calls to the `PLACES_COUNT` function.\nFor example, you want a single result showing the number of restaurants for\nthe following price levels within a specific area:\n\n- `PRICE_LEVEL_INEXPENSIVE`\n- `PRICE_LEVEL_MODERATE`\n- `PRICE_LEVEL_EXPENSIVE`\n- `PRICE_LEVEL_VERY_EXPENSIVE\"`\n\nIn this example, you create a loop to call the `PLACES_COUNT` function for each\nprice level, and insert the results of each call to a temporary table. You then\nquery the temporary table to display the results: \n\n```googlesql\n-- Create a temp table to hold the results.\nCREATE TEMP TABLE results (type STRING, count INT64);\n\n-- Create a loop that calls PLACES_COUNT for each price level.\nFOR types IN (SELECT type FROM UNNEST([\"PRICE_LEVEL_INEXPENSIVE\", \"PRICE_LEVEL_MODERATE\", \"PRICE_LEVEL_EXPENSIVE\", \"PRICE_LEVEL_VERY_EXPENSIVE\"]) as type)\nDO\n INSERT INTO results VALUES (types.type, `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(\n JSON_OBJECT(\n 'types', [\"restaurant\"],\n 'geography', ST_GEOGPOINT(-73.9857, 40.7484), -- Empire State Building\n 'geography_radius', 1000, -- Radius in meters\n 'business_status', ['OPERATIONAL'],\n 'price_level', [types.type]\n )));\nEND FOR;\n\n-- Query the table of results.\nSELECT * FROM results;\n```\n\nThe combined response:\n\nAnother option is to use the `UNION ALL` command to combine the results of\nmultiple `SELECT` statements. The following example shows the same results as\nfrom the previous example: \n\n```googlesql\nSELECT \"PRICE_LEVEL_INEXPENSIVE\" as price_level, `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(\n JSON_OBJECT(\n 'types', [\"restaurant\"],\n 'geography', ST_GEOGPOINT(-73.9857, 40.7484), -- Empire State Building\n 'geography_radius', 1000, -- Radius in meters\n 'business_status', ['OPERATIONAL'],\n 'price_level', ['PRICE_LEVEL_INEXPENSIVE']\n )\n) as count\n\nUNION ALL\n\nSELECT \"PRICE_LEVEL_MODERATE\" as price_level, `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(\n JSON_OBJECT(\n 'types', [\"restaurant\"],\n 'geography', ST_GEOGPOINT(-73.9857, 40.7484), -- Empire State Building\n 'geography_radius', 1000, -- Radius in meters\n 'business_status', ['OPERATIONAL'],\n 'price_level', ['PRICE_LEVEL_MODERATE']\n )\n) as count\n\nUNION ALL\n\nSELECT \"PRICE_LEVEL_EXPENSIVE\" as price_level, `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(\n JSON_OBJECT(\n 'types', [\"restaurant\"],\n 'geography', ST_GEOGPOINT(-73.9857, 40.7484), -- Empire State Building\n 'geography_radius', 1000, -- Radius in meters\n 'business_status', ['OPERATIONAL'],\n 'price_level', ['PRICE_LEVEL_EXPENSIVE']\n )\n) as count\n\nUNION ALL\n\nSELECT \"PRICE_LEVEL_VERY_EXPENSIVE\" as price_level, `maps-platform-analytics-hub.sample_places_insights_us.PLACES_COUNT`(\n JSON_OBJECT(\n 'types', [\"restaurant\"],\n 'geography', ST_GEOGPOINT(-73.9857, 40.7484), -- Empire State Building\n 'geography_radius', 1000, -- Radius in meters\n 'business_status', ['OPERATIONAL'],\n 'price_level', ['PRICE_LEVEL_VERY_EXPENSIVE']\n )\n) as count\n```"]]