Building a Route Search Function with Amazon Location SDK and API Key Function
I built a route search function with Amazon Location SDK and API key. This is an example of using the route search of the "Amazon Location SDK" released last year.
Published Feb 26, 2024
In the past, to use the Amazon Location Service, you had the option of configuring it manually or using Amplify Geo (although the route search functionality is not yet supported). However, with the release of the Amazon Location SDK and API Key feature last year, more options are now available, and the Amazon Location SDK makes manual configuration easier. I would like to explain the route search feature using this new functionality in this article.
The created environment is available on GitHub. Please use it.
Advance Preparation
Amazon Location Service #004 - API Key Creation (Maps)
Amazon Location Service #005 - API Key Creation (routing)
Amazon Location Service #005 - API Key Creation (routing)
- node v20.0.0
- npm v9.6.4
First, build an environment with the existing starter. Fork or download the package to your local environment and verify that it works.
Overall Configuration
Set the region, map API key, and map name created in the preliminaries to the env file.
Install the package
Start the local server
Next, install the necessary libraries for the Amazon Location SDK. The installation 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.
Install "amazon-location-utilities-auth-helper," a library that facilitates authentication with Amazon Location Service API keys and Cognito.
Install "amazon-location-utilities-datatypes," a library that converts Amazon Location Service responses to GeoJSON format.
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!
Finally, we will build the route search function. Some files are changed from the starter.
Set the region, map API key, map name, routing API key, and routing name created in the preliminaries to the env file.
Define the Amazon Location SDK.
Set up authentication for the API key.
Search for a route at the specified location.
Convert the routing response to GeoJSON.
Let's check with a simple local server.
References