Skip to content
aeropage-round-dark
Aeropage Documentation
Maps

icon picker
Addresses to Coordinates

Generate the coordinates of an address so that you can save it to Airtable and use it for the Map Component.

MapBox API

This script uses the MapBox API → you can create a free account and generate a token here :

Create an Account

image.png

Generate a Token

Create a token with the default settings - you don’t need to change anything.
image.png
info
Leave the tab open as you will need to come back and copy the token in later steps.

Airtable Setup

To trigger your automation, we recommed using a checkbox initially during testing - then later

Record / Field

Setup a new field with a checkbox, then check it for one record.
image.png

Trigger

Then create an automation with the trigger → when record matches conditions → [checkbox] is checked.
image.png

Run Script

After the trigger create a Run Script step.
image.png

Copy Script

Copy the script below. This script sends an address to Mapbox and returns the latitude and longitude coordinates of the given address.
/**
* This script returns the latitude and longitude of a given address by querying Mapbox through its API.
* It accepts Mapbox API access token and the Address field
*
* To get an access token, please go to
* https://account.mapbox.com/access-tokens
*/
const {address} = input.config();
const urlParams = new URLSearchParams({
q: address,
access_token: "YOUR_MAPBOX_API_TOKEN",
limit: "1"
});
const stringifiedUrlParams = urlParams?.toString();
const APIUrl = `https://api.mapbox.com/search/geocode/v6/forward?${stringifiedUrlParams}`;

const result = await fetch(
APIUrl,
{
method: "GET",
}
)
.then(res => res.json())
.catch(err => { throw err });

const latitude = result?.features?.[0]?.properties?.coordinates?.latitude;
const longitude = result?.features?.[0]?.properties?.coordinates?.longitude;

//Set the longitude and latitude as the outputs. Use this to save the coordinates to a table/view.
output.set("latitude", latitude)
output.set("longitude", longitude)

Input Variable → Address

We will need to put the address into the script so it can be converted into coordinates.

To do this we use an input variable → make sure it has the Name as address.
image.png

Mapbox Token

Copy the mapbox token and paste it into the script.
image.png
image.png

Test your Script

Click the test button and you should see it run successfully with input as the address and output as two coordinates.
image.png

Update Record

In the next step update the record Latitude and Longitude fields → using the outputs from the script.
image.png

Result

Once the script works, you’ll have coordinates you can plug into your map component.
image.png

Run Automatically

When you have confirmed it works for your records by triggering them with checkboxes - switch to an automation flow that works for your use case.
On Demand : when [coordinates] is empty and [address] is not empty → good for systems where new records are added from external sources.
Interval : every [day] find records where [same condition as above] and repeating group [run the script] then [update record] → good for systems where the addresses are added manually.

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.