Geocode addresses within Airtable

Topic Labels: Automations
619 0
Showing results for 
Search instead for 
Did you mean: 
4 - Data Explorer
4 - Data Explorer

Posting this here for anyone else who might find it helpful. While there are some great extensions for geocoding, I needed to simply convert an address into latitude and longitude and had a hard time finding a script to do it in Airtable + Google Maps API. 

I found this awesome script but had to modify it to only run on a particular view so that it didn't hit the automation / script limits. Here's my version for anyone looking for a way to geocode the record once it hits a particular view: 

Create number fields called Lat and Lng, get a Google Maps API key, create a view of records that have Address, but not Lat that can trigger an automation. 

let table = base.getTable('<TABLE NAME GOES HERE>');
let view = table.getView('<VIEW NAME GOES HERE>');
let result = await view.selectRecordsAsync({
sorts: [
{ field: 'Lat', direction: 'asc' },
{ field: 'Address', direction: 'asc' },
{ field: 'Lng', direction: 'asc' }


await Promise.all( record => {
let address = record.getCellValue('Address')
let lats = record.getCellValue('Lat')
let lngs = record.getCellValue('Lng')

if (!address) {

if (lats) {
console.log(`Skipping, location already exists: ${address}`)


console.log('Geocoding: ${address}')

let geo = await fetch(
' ',
).then(r => r.json())

if (!geo.results || geo.results.length === 0) {
console.log(`No geocode results found for: ${address}`)

let {
geometry: {
location: { lat, lng }
} = geo.results[0]

return await table.updateRecordAsync(record, {
Lat: lat,
Lng: lng

console.log('# Done!')

0 Replies 0