Airtable Automation Script to Find Distance Given Lat Long Update Field

Ok, total noob here. Figured out a bunch but need help.
Data comes into a table starting a new record including the name of the person, the name of the location they are at. Also is the lat/long of the place they are physically at and the lat/long of the place they’re supposed to be. Each lat/long is separated in their own fields (lat1,lon1,lat2,lon2). There is a final field (Distance) to which I want to calculate the straight line distance between those two points.
I have found some javascript in other forum answers but I cannot figure out how to use the four data fields (lat1,lon1,lat2,lon2) with a script to calculate the distance and return that value to the “Distance” field.
I currently have an automation that when a new record is created, it performs the script…but then where do I go from there?
Please assist. Thanks.

Hi @Paul_Tong ,
What distance measurement do you wish to use? mi, km, ft?
Do you want straight line or greater circle? Is your distance in the air or on the ground? If on the ground do you need to accommodate for roads/traffic and obstacles?

This past post might be helpful to get you started. How to set up a table containing distances between locations for use in invoicing

I’ll look at that.

To answer your question, unit of measure is irrelevant. That is a simple change of the value of whatever you set the R to be. I know the basic formula and have seen the javascript code in other parts of this forum. What I don’t understand is how to code the values of lat1, lon1, lat2, lon2 that is already in the record and return that value to another field (let’s call it “Distance”). I think the common method is the Haversine formula which is what I’ll use. Because Airtable has yet to make sine, cosine, and tangent as part of their formula options, I have to learn scripting to make it work.