AWS

Create Your Own Geocode Serverless Application

By Michael Palermo | 23 January 2020

Geocoding is an essential feature of location services. With geocoding we can attribute friendly names to geolocation coordinates or vice-versa. AWS developers can take quickly create add this feature within their own development environment using the AWS Serverless Application Repository

This post will show how you can deploy HERE Geocode Serverless Application for use in your development projects. This will allow you to access geocoding features from HERE via your own custom API! To accomplish this, you will need credentials at the following:


Deploying the HERE Geocode Serverless App

After account credentials are confirmed, to find the HERE MapImage application, browse to the AWS Serverless Application Repository.

AWS Serverless Application Browse

After clicking the "Browse all applications" button, you will be prompted to do your search. Type "geocode" as shown below, then select the Geocode title in the results shown.

2020sar-find-geocode

Once the landing page for the Geocode application is shown, enter your HERE API Key in the highlighted area shown below, then deploy.

2020sar-geocode-credentials

It will take a little time for the deployment process to complete. You are prepared for the next step once you see the "Your application has been deployed" message shown.


Accessing Your Geocode Application

Part of the newly created Geocode application is the API endpoint to execute it. The following screen capture shows how to execute a simple test via the AWS API Gateway:

2020sar-geocode-api-test

With the above URL construct in mind, consider the following script in an HTML client:


let API_ID = "your-api-id";
function processForm() {     let place = document.getElementById("placeInput").value;     console.log(place);     if (place == "") {         alert("Need a place!");         return false;     }     invokeGeoAPI(place); } function invokeGeoAPI(place) {     fetch(`https://${API_ID}.execute-api.us-east-1.amazonaws.com/Prod/geocode/api/geocoder/6.2/geocode.json?searchtext=${place}`)         .then(response => response.json())         .then(response => {             console.log(response);         }); }

The above script calls a constructed URL which points to the new geocode application via Amazon API Gateway. You must replace the value of API_ID with the value generated from your API Gateway when the Geocode app was deployed. After the fetch completes the entire response is simply logged.

NOTE: You may need to uncomment a line of code in the newly generated lambda to enable CORS.

For more information, please enjoy our recorded session on this topic: