From 6ba9b776e737cb0b4811489e5663f1bc928711e6 Mon Sep 17 00:00:00 2001 From: William French Date: Wed, 22 Apr 2026 09:05:05 -0700 Subject: [PATCH] feat: Migrates the geocoding-region-es sample to js-api-samples. --- samples/geocoding-region-es/README.md | 41 +++++++++++++++++++++++ samples/geocoding-region-es/index.html | 22 ++++++++++++ samples/geocoding-region-es/index.ts | 38 +++++++++++++++++++++ samples/geocoding-region-es/package.json | 14 ++++++++ samples/geocoding-region-es/style.css | 18 ++++++++++ samples/geocoding-region-es/tsconfig.json | 9 +++++ 6 files changed, 142 insertions(+) create mode 100644 samples/geocoding-region-es/README.md create mode 100644 samples/geocoding-region-es/index.html create mode 100644 samples/geocoding-region-es/index.ts create mode 100644 samples/geocoding-region-es/package.json create mode 100644 samples/geocoding-region-es/style.css create mode 100644 samples/geocoding-region-es/tsconfig.json diff --git a/samples/geocoding-region-es/README.md b/samples/geocoding-region-es/README.md new file mode 100644 index 000000000..83e6c3ca2 --- /dev/null +++ b/samples/geocoding-region-es/README.md @@ -0,0 +1,41 @@ +# Google Maps JavaScript Sample + +## geocoding-region-es + +This sample demonstrates how to geocode using the Spanish region code. + +## Setup + +### Before starting run: + +`npm i` + +### Run an example on a local web server + +`cd samples/geocoding-region-es` +`npm start` + +### Build an individual example + +`cd samples/geocoding-region-es` +`npm run build` + +From 'samples': + +`npm run build --workspace=geocoding-region-es/` + +### Build all of the examples. + +From 'samples': + +`npm run build-all` + +### Run lint to check for problems + +`cd samples/geocoding-region-es` +`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). diff --git a/samples/geocoding-region-es/index.html b/samples/geocoding-region-es/index.html new file mode 100644 index 000000000..4c1bc62aa --- /dev/null +++ b/samples/geocoding-region-es/index.html @@ -0,0 +1,22 @@ + + + + + + Geocoding Region - ES + + + + + + + + + + + diff --git a/samples/geocoding-region-es/index.ts b/samples/geocoding-region-es/index.ts new file mode 100644 index 000000000..a7a32277a --- /dev/null +++ b/samples/geocoding-region-es/index.ts @@ -0,0 +1,38 @@ +/** + * @license + * Copyright 2026 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +// @ts-nocheck TODO remove when fixed + +// [START maps_js_geocoding_region_es] +async function initMap(): Promise { + await Promise.all([ + google.maps.importLibrary("maps"), + google.maps.importLibrary("geocoding"), + google.maps.importLibrary("marker"), + ]); + + const mapElement = document.querySelector("gmp-map") as google.maps.MapElement; + const innerMap = mapElement.innerMap; + const geocoder = new google.maps.Geocoder(); + + geocoder + .geocode({ address: "Toledo" }) + .then((response) => { + const position = response.results[0].geometry.location; + + innerMap.setCenter(position); + new google.maps.marker.AdvancedMarkerElement({ + map: innerMap, + position, + }); + }) + .catch((e) => + window.alert("Geocode was not successful for the following reason: " + e) + ); +} + +initMap(); +// [END maps_js_geocoding_region_es] diff --git a/samples/geocoding-region-es/package.json b/samples/geocoding-region-es/package.json new file mode 100644 index 000000000..23b2e9ee8 --- /dev/null +++ b/samples/geocoding-region-es/package.json @@ -0,0 +1,14 @@ +{ + "name": "@js-api-samples/geocoding-region-es", + "version": "1.0.0", + "scripts": { + "build": "tsc && bash ../jsfiddle.sh geocoding-region-es && bash ../app.sh geocoding-region-es && bash ../docs.sh geocoding-region-es && npm run build:vite --workspace=. && bash ../dist.sh geocoding-region-es", + "test": "tsc && npm run build:vite --workspace=.", + "start": "tsc && vite build --base './' && vite", + "build:vite": "vite build --base './'", + "preview": "vite preview" + }, + "dependencies": { + + } +} diff --git a/samples/geocoding-region-es/style.css b/samples/geocoding-region-es/style.css new file mode 100644 index 000000000..f4c07e1bb --- /dev/null +++ b/samples/geocoding-region-es/style.css @@ -0,0 +1,18 @@ +/** + * @license + * Copyright 2026 Google LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +/* [START maps_js_geocoding_region_es] */ + +/* + * Optional: Makes the sample page fill the window. + */ +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +/* [END maps_js_geocoding_region_es] */ \ No newline at end of file diff --git a/samples/geocoding-region-es/tsconfig.json b/samples/geocoding-region-es/tsconfig.json new file mode 100644 index 000000000..5ba470c05 --- /dev/null +++ b/samples/geocoding-region-es/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "rootDir": "." + }, + "include": [ + "./*.ts", + ] +}