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

Create an API key for Amazon Location Service

Execution environment

  • node v20.0.0
  • npm v9.6.4

MapLibre GL JS and Amazon Location Service Starter

First, build an environment with the existing starter. Fork or download the package to your local environment and verify that it works.

maplibregljs-amazon-location-service-starter

Overall Configuration

.env

Set the region, map API key, and map name created in the preliminaries to the env file.
Install the package
Start the local server

Install Amazon Location SDK

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.

client-location

Install the AWS SDK. "client-location" is an SDK that allows you to manipulate the Amazon Location Service.

amazon-location-utilities-auth-helper

Install "amazon-location-utilities-auth-helper," a library that facilitates authentication with Amazon Location Service API keys and Cognito.

amazon-location-utilities-datatypes

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!

Building a Route Search Function

Finally, we will build the route search function. Some files are changed from the starter.

package.json

.env

Set the region, map API key, map name, routing API key, and routing name created in the preliminaries to the env file.

main.ts

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

Comments