Skip to content

Commit aff1ea8

Browse files
authored
Merge pull request #29 from googlemaps-samples/feat/demo-price-filter
feat(demo): Add Price Level filter and expand H3 resolution limits
2 parents d4ca5a4 + 14415a4 commit aff1ea8

6 files changed

Lines changed: 32 additions & 11 deletions

File tree

places_insights/places-insights-demo/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ This application uses client-side OAuth 2.0 to authorize users to run BigQuery q
4949
3. For "Application type", select **Web application**.
5050
4. Give it a name (e.g., "Places Insights Demo").
5151
5. Under **Authorized JavaScript origins**, click **+ ADD URI**.
52-
6. Enter the origin for your local development server. For most servers, this is `http://localhost:8000`.
52+
6. Enter the origin for your local development server. For most servers, this is `http://localhost:8000`.
5353
7. Click **CREATE**.
5454
8. Copy the **Your Client ID** value. You will need this in the next step.
5555

@@ -118,12 +118,12 @@ For a detailed walkthrough, click the **Help** button in the application's sideb
118118
* **Places Count Per H3 (Function):** Uses server-side BigQuery functions for high-performance density mapping. This mode supports **low counts (0-4)** and **sample place markers**.
119119
4. **Apply Filters:** Narrow your search using the collapsible filter sections:
120120
* **Place Types:** Select types and optionally check **"Match Primary Type Only"** for stricter filtering.
121-
* **Attributes:** Filter by Rating, Business Status (Operational/Closed), Price, etc.
121+
* **Attributes:** Filter by Price Level, Rating, Business Status (Operational/Closed), and various amenities (e.g., "Offers Delivery").
122122
* **Opening Hours:** Filter by day and time (Standard modes only).
123123
* **Brands:** Filter by brand name or category (US Standard mode only).
124124
5. **Visualize:**
125125
* Leave **Show H3 Density Map** unchecked for simple aggregate counts (Standard modes only).
126-
* Check the box to visualize the results as a color-coded heatmap of hexagonal cells.
126+
* Check the box to visualize the results as a color-coded heatmap of hexagonal cells. You can use the **H3 Resolution slider** (supporting up to resolution 11) to adjust the granularity of the cells.
127127
6. **Run Search:** Click the "Run Search" button to execute the query and see the results on the map.
128128

129129
### Interactive Features (H3 Function Mode)

places_insights/places-insights-demo/help.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ function generateGuideHtml() {
132132
<li><strong>Included Place Types:</strong> Start typing a place category (e.g., <code>restaurant</code>, <code>park</code>) and click a suggestion to add it as a tag.</li>
133133
<li><strong>Match Primary Type Only:</strong> Check this box to search strictly for places where the selected type is their <em>primary</em> classification (e.g., finding a "Restaurant" that is primarily a restaurant, not a hotel with a restaurant).</li>
134134
<li><strong>Business Status:</strong> Filter places by their operational status (Operational, Closed Temporarily, Closed Permanently, or Any). Default is <strong>Operational</strong>.</li>
135-
<li><strong>Attribute Filters:</strong> Set min/max ratings or select checkboxes for amenities (e.g., "Offers Delivery").</li>
135+
<li><strong>Attribute Filters:</strong> Filter by Price Level, set min/max ratings, or select checkboxes for amenities (e.g., "Offers Delivery").</li>
136136
<li><strong>Opening Hours:</strong> Select a <strong>Day of Week</strong> and time window (Not available in H3 Function mode).</li>
137137
<li><strong>Brand Filters (US Only):</strong> Filter by Brand Category or Brand Name (Not available in H3 Function mode).</li>
138138
</ul>
139139
140140
<h2>5. Choosing Your Visualization</h2>
141141
<ul>
142142
<li><strong>Simple Count (Default):</strong> Results are displayed as numbers in a pop-up window.</li>
143-
<li><strong>H3 Density Map:</strong> Check the <strong>Show H3 Density Map</strong> box to see a heatmap. Use the <strong>H3 Resolution</strong> slider to change the cell size. (This is always enabled in H3 Function mode).</li>
143+
<li><strong>H3 Density Map:</strong> Check the <strong>Show H3 Density Map</strong> box to see a heatmap. Use the <strong>H3 Resolution</strong> slider (up to resolution 11) to change the cell size. (This is always enabled in H3 Function mode).</li>
144144
</ul>
145145
146146
<h2>6. Running a Query and Managing the App</h2>

places_insights/places-insights-demo/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ <h1>Places Insights</h1>
155155
<option value="">Any Status</option>
156156
</select>
157157
</div>
158+
<div class="control-group">
159+
<label for="price-level-select">Price Level</label>
160+
<select id="price-level-select">
161+
<option value="" selected>All Price Levels</option>
162+
<option value="PRICE_LEVEL_FREE">Free</option>
163+
<option value="PRICE_LEVEL_INEXPENSIVE">Inexpensive</option>
164+
<option value="PRICE_LEVEL_MODERATE">Moderate</option>
165+
<option value="PRICE_LEVEL_EXPENSIVE">Expensive</option>
166+
<option value="PRICE_LEVEL_VERY_EXPENSIVE">Very Expensive</option>
167+
</select>
168+
</div>
158169
<div class="rating-inputs">
159170
<div class="control-group"><label for="min-rating-input">Min Rating</label><input type="number" id="min-rating-input" min="1" max="5" step="0.1" placeholder="1.0"></div>
160171
<div class="control-group"><label for="max-rating-input">Max Rating</label><input type="number" id="max-rating-input" min="1" max="5" step="0.1" placeholder="5.0"></div>

places_insights/places-insights-demo/map.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ function handleDemoTypeChange(e) {
7474
h3Toggle.checked = true;
7575
h3Toggle.disabled = true;
7676

77-
// Show Slider with Max 8
77+
// Show Slider with Max 11
7878
document.getElementById('h3-resolution-controls').classList.remove('hidden');
7979
const h3Slider = document.getElementById('h3-resolution-slider');
80-
h3Slider.max = '8';
81-
if (parseInt(h3Slider.value) > 8) {
82-
h3Slider.value = '8';
83-
document.getElementById('h3-resolution-value').textContent = '8';
80+
h3Slider.max = '11';
81+
if (parseInt(h3Slider.value) > 11) {
82+
h3Slider.value = '11';
83+
document.getElementById('h3-resolution-value').textContent = '11';
8484
}
8585

8686
// Always Hide Brand Filters for Function mode

places_insights/places-insights-demo/query.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ async function runQuery() {
193193

194194
const bizStatus = document.getElementById('business-status-select').value;
195195
if (bizStatus) allFilters.push(`places.business_status = '${bizStatus}'`);
196+
197+
const priceLevel = document.getElementById('price-level-select').value;
198+
if (priceLevel) allFilters.push(`places.price_level = '${priceLevel}'`);
196199

197200
// Brand Filters (only applicable here, not in H3 Function)
198201
const brandNames = [...document.querySelectorAll('#selected-brands-list span')].map(s => s.textContent);
@@ -401,7 +404,13 @@ function buildH3FunctionQuery(countryCode) {
401404
if (!isNaN(minRating)) jsonParts.push(`'min_rating', ${minRating}`);
402405
if (!isNaN(maxRating)) jsonParts.push(`'max_rating', ${maxRating}`);
403406

404-
// 4. Boolean Attributes
407+
// 4. Price Level
408+
const priceLevel = document.getElementById('price-level-select').value;
409+
if (priceLevel) {
410+
jsonParts.push(`'price_level', ['${priceLevel}']`);
411+
}
412+
413+
// 5. Boolean Attributes
405414
const attributes = [...document.querySelectorAll('.attribute-filter:checked')].map(cb => cb.name);
406415
attributes.forEach(attr => {
407416
jsonParts.push(`'${attr}', TRUE`);

places_insights/places-insights-demo/ui.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function resetSidebarUI(targetMode = 'circle-search') {
8282
document.getElementById('min-rating-input').value = '';
8383
document.getElementById('max-rating-input').value = '';
8484
document.getElementById('business-status-select').value = 'OPERATIONAL';
85+
document.getElementById('price-level-select').value = '';
8586
document.querySelectorAll('.attribute-filter').forEach(cb => cb.checked = false);
8687

8788
// Reset Time

0 commit comments

Comments
 (0)