-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Migrates the Place AC data simple sample. #922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f76c879
feat: Migrates the Place AC data simple sample.
willum070 1d80dd6
Apply review comments
willum070 83c6b0b
Merge branch 'main' into migrate-place-ac-simple
willum070 ea8283d
Fix DOCTYPE declaration and add trailing line break
willum070 194e093
Add newline at end of style.css
willum070 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Google Maps JavaScript Sample | ||
|
|
||
| ## place-autocomplete-data-simple | ||
|
|
||
| The place-autocomplete-data-simple sample demonstrates making a single request for Place predictions, | ||
| then requests Place Details for the first result. | ||
|
|
||
| ## Setup | ||
|
|
||
| ### Before starting run: | ||
|
|
||
| `npm i` | ||
|
|
||
| ### Run an example on a local web server | ||
|
|
||
| `cd samples/place-autocomplete-data-simple` | ||
| `npm start` | ||
|
|
||
| ### Build an individual example | ||
|
|
||
| `cd samples/place-autocomplete-data-simple` | ||
| `npm run build` | ||
|
|
||
| From 'samples': | ||
|
|
||
| `npm run build --workspace=place-autocomplete-data-simple/` | ||
|
|
||
| ### Build all of the examples. | ||
|
|
||
| From 'samples': | ||
|
|
||
| `npm run build-all` | ||
|
|
||
| ### Run lint to check for problems | ||
|
|
||
| `cd samples/place-autocomplete-data-simple` | ||
| `npx eslint index.ts` | ||
|
|
||
| ## Feedback | ||
|
|
||
| For feedback related to this sample, please open a new issue on | ||
| [GitHub](https://github.com/googlemaps-samples/js-api-samples/issues). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <!DOCTYPE html> | ||
| <!-- | ||
| @license | ||
| Copyright 2025 Google LLC. All Rights Reserved. | ||
| SPDX-License-Identifier: Apache-2.0 | ||
| --> | ||
| <!-- [START maps_place_autocomplete_data_simple] --> | ||
| <html> | ||
| <head> | ||
| <title>Place Autocomplete Data API Predictions</title> | ||
|
|
||
| <link rel="stylesheet" type="text/css" href="./style.css" /> | ||
| <script type="module" src="./index.js"></script> | ||
| <!-- prettier-ignore --> | ||
| <script>(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))}) | ||
| ({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "weekly"});</script> | ||
| </head> | ||
| <body> | ||
| <!-- [START maps_place_autocomplete_data_simple_html] --> | ||
| <div id="title"></div> | ||
| <ul id="results"></ul> | ||
| <p><span id="prediction"></span></p> | ||
| <img | ||
| class="powered-by-google" | ||
| src="./powered_by_google_on_white.png" | ||
| alt="Powered by Google" | ||
| /> | ||
| <!-- [END maps_place_autocomplete_data_simple_html] --> | ||
|
|
||
| </body> | ||
| </html> | ||
| <!-- [END maps_place_autocomplete_data_simple] --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| // [START maps_place_autocomplete_data_simple] | ||
| async function init() { | ||
| const { Place, AutocompleteSessionToken, AutocompleteSuggestion } = | ||
| (await google.maps.importLibrary("places")) as google.maps.PlacesLibrary; | ||
|
|
||
| // [START maps_place_autocomplete_data_simple_request] | ||
| // Add an initial request body. | ||
| // [START maps_place_autocomplete_data_simple_request_body] | ||
| let request = { | ||
| input: "Tadi", | ||
| locationRestriction: { | ||
| west: -122.44, | ||
| north: 37.8, | ||
| east: -122.39, | ||
| south: 37.78, | ||
| }, | ||
| origin: { lat: 37.7893, lng: -122.4039 }, | ||
| includedPrimaryTypes: ["restaurant"], | ||
| language: "en-US", | ||
| region: "us", | ||
| }; | ||
| // [END maps_place_autocomplete_data_simple_request_body] | ||
|
|
||
| // [START maps_place_autocomplete_data_simple_token] | ||
| // Create a session token. | ||
| const token = new AutocompleteSessionToken(); | ||
| // Add the token to the request. | ||
| // @ts-ignore | ||
| request.sessionToken = token; | ||
| // [END maps_place_autocomplete_data_simple_token] | ||
| // [END maps_place_autocomplete_data_simple_request] | ||
| // [START maps_place_autocomplete_data_simple_get_suggestions] | ||
| // Fetch autocomplete suggestions. | ||
| const { suggestions } = | ||
| await AutocompleteSuggestion.fetchAutocompleteSuggestions(request); | ||
|
|
||
| const title = document.getElementById("title") as HTMLElement; | ||
| title.appendChild( | ||
| document.createTextNode('Query predictions for "' + request.input + '":') | ||
| ); | ||
|
|
||
| const resultsElement = document.getElementById("results") as HTMLElement; | ||
|
|
||
| for (let suggestion of suggestions) { | ||
| const placePrediction = suggestion.placePrediction; | ||
|
|
||
| // Create a new list element. | ||
| const listItem = document.createElement("li"); | ||
|
|
||
| listItem.appendChild( | ||
| document.createTextNode(placePrediction!.text.toString()) | ||
| ); | ||
| resultsElement.appendChild(listItem); | ||
| } | ||
| // [END maps_place_autocomplete_data_simple_get_suggestions] | ||
|
|
||
| // [START maps_place_autocomplete_data_simple_prediction] | ||
| let place = suggestions[0].placePrediction!.toPlace(); // Get first predicted place. | ||
| // [START maps_place_autocomplete_data_simple_fetch] | ||
| await place.fetchFields({ | ||
| fields: ["displayName", "formattedAddress"], | ||
| }); | ||
| // [END maps_place_autocomplete_data_simple_fetch] | ||
|
|
||
| const placeInfo = document.getElementById("prediction") as HTMLElement; | ||
| placeInfo.textContent = | ||
| `First predicted place: ${place.displayName}: ${place.formattedAddress}`; | ||
| // [END maps_place_autocomplete_data_simple_prediction] | ||
| } | ||
|
|
||
| init(); | ||
| // [END maps_place_autocomplete_data_simple] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "name": "@js-api-samples/place-autocomplete-data-simple", | ||
| "version": "1.0.0", | ||
| "scripts": { | ||
| "build": "tsc && bash ../jsfiddle.sh place-autocomplete-data-simple && bash ../app.sh place-autocomplete-data-simple && bash ../docs.sh place-autocomplete-data-simple && npm run build:vite --workspace=. && bash ../dist.sh place-autocomplete-data-simple", | ||
| "test": "tsc && npm run build:vite --workspace=.", | ||
| "start": "tsc && vite build --base './' && vite", | ||
| "build:vite": "vite build --base './'", | ||
| "preview": "vite preview" | ||
| }, | ||
| "dependencies": { | ||
|
|
||
| } | ||
| } |
Binary file added
BIN
+8.96 KB
samples/place-autocomplete-data-simple/public/powered_by_google_on_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| /* [START maps_place_autocomplete_data_simple] */ | ||
| /* | ||
| * Always set the map height explicitly to define the size of the div element | ||
| * that contains the map. | ||
| */ | ||
| #map { | ||
| height: 100%; | ||
| } | ||
|
|
||
| /* | ||
| * Optional: Makes the sample page fill the window. | ||
| */ | ||
| html, | ||
| body { | ||
| height: 100%; | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
|
|
||
| /* [END maps_place_autocomplete_data_simple] */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "module": "esnext", | ||
| "target": "esnext", | ||
| "strict": true, | ||
| "noImplicitAny": false, | ||
| "lib": [ | ||
| "es2015", | ||
| "esnext", | ||
| "es6", | ||
| "dom", | ||
| "dom.iterable" | ||
| ], | ||
| "moduleResolution": "Node", | ||
| "jsx": "preserve" | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.