diff --git a/samples/add-map/index.html b/samples/add-map/index.html index bed68d36..4ce6e8ad 100644 --- a/samples/add-map/index.html +++ b/samples/add-map/index.html @@ -1,8 +1,18 @@ diff --git a/samples/add-map/index.js b/samples/add-map/index.js index 3f81b4a7..82fa8c3a 100644 --- a/samples/add-map/index.js +++ b/samples/add-map/index.js @@ -1,9 +1,19 @@ "use strict"; -/** - * @license - * Copyright 2019 Google LLC. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ // [START maps_add_map] // Initialize and add the map let map; diff --git a/samples/add-map/index.ts b/samples/add-map/index.ts index 1c704dce..03fa1ca9 100644 --- a/samples/add-map/index.ts +++ b/samples/add-map/index.ts @@ -1,8 +1,18 @@ -/** - * @license - * Copyright 2019 Google LLC. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ // [START maps_add_map] // Initialize and add the map diff --git a/samples/add-map/style.css b/samples/add-map/style.css index 5e8d5bfc..5d2c15ab 100644 --- a/samples/add-map/style.css +++ b/samples/add-map/style.css @@ -1,8 +1,18 @@ -/** - * @license - * Copyright 2019 Google LLC. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ /* [START maps_add_map] */ /* * Always set the map height explicitly to define the size of the div element diff --git a/samples/map-simple/index.html b/samples/map-simple/index.html index bc9b11b2..961246d0 100644 --- a/samples/map-simple/index.html +++ b/samples/map-simple/index.html @@ -1,8 +1,18 @@ diff --git a/samples/map-simple/index.js b/samples/map-simple/index.js index fa1e36c7..99f4f0df 100644 --- a/samples/map-simple/index.js +++ b/samples/map-simple/index.js @@ -1,9 +1,19 @@ "use strict"; -/** - * @license - * Copyright 2019 Google LLC. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ // [START maps_map_simple] let map; async function initMap() { diff --git a/samples/map-simple/index.ts b/samples/map-simple/index.ts index 9fb4273f..63cd0e42 100644 --- a/samples/map-simple/index.ts +++ b/samples/map-simple/index.ts @@ -1,8 +1,18 @@ -/** - * @license - * Copyright 2019 Google LLC. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ // [START maps_map_simple] let map: google.maps.Map; diff --git a/samples/map-simple/style.css b/samples/map-simple/style.css index da3022b8..46cae468 100644 --- a/samples/map-simple/style.css +++ b/samples/map-simple/style.css @@ -1,8 +1,18 @@ -/** - * @license - * Copyright 2019 Google LLC. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ /* [START maps_map_simple] */ /* * Always set the map height explicitly to define the size of the div element diff --git a/samples/place-text-search/README.md b/samples/place-text-search/README.md new file mode 100644 index 00000000..e89ad5bb --- /dev/null +++ b/samples/place-text-search/README.md @@ -0,0 +1,32 @@ +# Google Maps JavaScript Sample + +This sample is generated from @googlemaps/js-samples located at +https://github.com/googlemaps-samples/js-api-samples. + +## Setup + +### Before starting run: + +`$npm i` + +### Run an example on a local web server + +First `cd` to the folder for the sample to run, then: + +`$npm start` + +### Build an individual example + +From `samples/`: + +`$npm run build --workspace=sample-name/` + +### Build all of the examples. + +From `samples/`: +`$npm run build-all` + +## Feedback + +For feedback related to this sample, please open a new issue on +[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues). \ No newline at end of file diff --git a/samples/place-text-search/index.html b/samples/place-text-search/index.html new file mode 100644 index 00000000..849acab9 --- /dev/null +++ b/samples/place-text-search/index.html @@ -0,0 +1,33 @@ + + + + + + Text Search + + + + + +
+ + + + + + diff --git a/samples/place-text-search/index.js b/samples/place-text-search/index.js new file mode 100644 index 00000000..a09d082f --- /dev/null +++ b/samples/place-text-search/index.js @@ -0,0 +1,69 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ +// [START maps_place_text_search] +let map; +let center; +async function initMap() { + const { Map } = await google.maps.importLibrary("maps"); + center = { lat: 37.4161493, lng: -122.0812166 }; + map = new Map(document.getElementById('map'), { + center: center, + zoom: 11, + mapId: 'DEMO_MAP_ID', + }); + findPlaces(); +} +async function findPlaces() { + const { Place } = await google.maps.importLibrary("places"); + const { AdvancedMarkerElement } = await google.maps.importLibrary("marker"); + // [START maps_place_text_search_request] + const request = { + textQuery: 'Tacos in Mountain View', + fields: ['displayName', 'location', 'businessStatus'], + includedType: 'restaurant', + locationBias: { lat: 37.4161493, lng: -122.0812166 }, + isOpenNow: true, + language: 'en-US', + maxResultCount: 8, + minRating: 3.2, + region: 'us', + useStrictTypeFiltering: false, + }; + //@ts-ignore + const { places } = await Place.searchByText(request); + // [END maps_place_text_search_request] + if (places.length) { + console.log(places); + const { LatLngBounds } = await google.maps.importLibrary("core"); + const bounds = new LatLngBounds(); + // Loop through and get all the results. + places.forEach((place) => { + const markerView = new AdvancedMarkerElement({ + map, + position: place.location, + title: place.displayName, + }); + bounds.extend(place.location); + console.log(place); + }); + map.fitBounds(bounds); + } + else { + console.log('No results'); + } +} +initMap(); +export {}; diff --git a/samples/place-text-search/index.ts b/samples/place-text-search/index.ts new file mode 100644 index 00000000..9cef85b9 --- /dev/null +++ b/samples/place-text-search/index.ts @@ -0,0 +1,83 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +// [START maps_place_text_search] +let map; +let center; + +async function initMap() { + const { Map } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary; + + center = { lat: 37.4161493, lng: -122.0812166 }; + map = new Map(document.getElementById('map') as HTMLElement, { + center: center, + zoom: 11, + mapId: 'DEMO_MAP_ID', + }); + + findPlaces(); +} + +async function findPlaces() { + const { Place } = await google.maps.importLibrary("places") as google.maps.PlacesLibrary; + const { AdvancedMarkerElement } = await google.maps.importLibrary("marker") as google.maps.MarkerLibrary; + // [START maps_place_text_search_request] + const request = { + textQuery: 'Tacos in Mountain View', + fields: ['displayName', 'location', 'businessStatus'], + includedType: 'restaurant', + locationBias: { lat: 37.4161493, lng: -122.0812166 }, + isOpenNow: true, + language: 'en-US', + maxResultCount: 8, + minRating: 3.2, + region: 'us', + useStrictTypeFiltering: false, + }; + + //@ts-ignore + const { places } = await Place.searchByText(request); + // [END maps_place_text_search_request] + + if (places.length) { + console.log(places); + + const { LatLngBounds } = await google.maps.importLibrary("core") as google.maps.CoreLibrary; + const bounds = new LatLngBounds(); + + // Loop through and get all the results. + places.forEach((place) => { + const markerView = new AdvancedMarkerElement({ + map, + position: place.location, + title: place.displayName, + }); + + bounds.extend(place.location as google.maps.LatLng); + console.log(place); + }); + + map.fitBounds(bounds); + + } else { + console.log('No results'); + } +} + +initMap(); +// [END maps_place_text_search] + +export { }; diff --git a/samples/place-text-search/package.json b/samples/place-text-search/package.json new file mode 100644 index 00000000..1d5e7dad --- /dev/null +++ b/samples/place-text-search/package.json @@ -0,0 +1,12 @@ +{ + "name": "@js-api-samples/place-text-search", + "version": "1.0.0", + "scripts": { + "build": "tsc && bash ../jsfiddle.sh place-text-search && bash ../app.sh place-text-search && bash ../docs.sh place-text-search", + "build": "tsc && bash ../jsfiddle.sh place-text-search && bash ../app.sh place-text-search && bash ../docs.sh place-text-search && vite build --base './'", + "start": "tsc && vite build --base './' && vite" + }, + "dependencies": { + + } +} diff --git a/samples/place-text-search/place-text-search.jshtml b/samples/place-text-search/place-text-search.jshtml new file mode 100644 index 00000000..4dc90aa0 --- /dev/null +++ b/samples/place-text-search/place-text-search.jshtml @@ -0,0 +1,19 @@ + +{% spaceless %}{% include "maps/documentation/javascript/examples/full/_apikey.html" %}{% endspaceless %} + + + + + Text Search + + + +{% includecode content_path="maps/documentation/javascript/examples/samples/place-text-search/index.html" region_tag="maps_place_text_search_body" html_escape="False" %} +{{ api_loader_dynamic }} + + + diff --git a/samples/place-text-search/style.css b/samples/place-text-search/style.css new file mode 100644 index 00000000..659b261e --- /dev/null +++ b/samples/place-text-search/style.css @@ -0,0 +1,35 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ +/* [START maps_place_text_search] */ +/* + * 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_text_search] */ \ No newline at end of file diff --git a/samples/place-text-search/tsconfig.json b/samples/place-text-search/tsconfig.json new file mode 100644 index 00000000..366aabb0 --- /dev/null +++ b/samples/place-text-search/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "module": "esnext", + "target": "esnext", + "strict": true, + "noImplicitAny": false, + "lib": [ + "es2015", + "esnext", + "es6", + "dom", + "dom.iterable" + ], + "moduleResolution": "Node", + "jsx": "preserve" + } +}