I built an address search function with Amazon Location SDK and API key. 🎉
In the past, to use the Amazon Location Service, you had the option of configuring it manually or using Amplify Geo. However, with the release of the Amazon Location SDK and API Key feature this year, more options are now available, and the Amazon Location SDK makes manual configuration easier. I would like to explain the address search feature using this new functionality in this article.
The created environment is available on GitHub. Please use it!
How to use the MapLibre GL JS and Amazon Location Service starter
Use the existing starter to build an address search function. Fork or download the package to your local environment and verify it works.
Install the package
npm install
Start local server
npm run dev
Install Amazon Location SDK
Next, install the necessary libraries for the Amazon Location SDK. Installing it will make it easier to authenticate the API and combine it with MapLibre GL JS.
Install the AWS SDK. "client-location" is an SDK that allows you to manipulate the Amazon Location Service.
npm install @aws-sdk/client-location
Install "amazon-location-utilities-auth-helper," a library that facilitates authentication with Amazon Location Service API keys and Cognito.
I contributed to "amazon-location-utilities-datatypes" to add an optional feature because it was sometimes difficult to use in combination with MapLibre GL JS!
Open-source projects and sample codes from AWS Geospatial - AWS Geospatial
github.com
Building an Address Search Function
Finally, we will build the address search function. Some files are changed from the starter.
Overall Configuration
package.json
{"name":"maplibregljs-amazon-location-service-place-indexes-starter","version":"3.3.1","description":"","scripts":{"dev":"vite","build":"tsc && vite build","preview":"vite preview"},"keywords":[],"author":"MapLibre User Group Japan","license":"ISC","devDependencies":{"typescript":"^5.2.2","vite":"^4.4.9"},"dependencies":{"@aws-sdk/client-location":"^3.433.0","@aws/amazon-location-utilities-auth-helper":"^1.0.2","@aws/amazon-location-utilities-datatypes":"^1.0.3","maplibre-gl":"^3.3.1"}}
.env
Set the region, map API key, map name, geocoding API key, and geocoding name created in the preliminaries to the env file.