I have a parent table of Addresses (with LatLongs) and a child table of Viewings. When creating a new viewing and selecting an address, I want to display a show column with a list of the other addresses and their calculated distances from the selected one. Any idea how to do this?
I understand how to get a list of the other addresses’ latlongs but not how to calculate distance for each from selected address
In general, to show the list of other addresses, you may want to restrict the number other addresses and their distance being displayed. For example other addresses within say same zip code or state or city from the selected address that selects a reasonably finite number of nearby addresses.
To calculate distance on the fly from the selected address, I believe you may need an automation or a reference action called through the automation.
I believe the setup may be a bit elaborate needing a couple of columns to be added and an automation to be set up. I will work out and post further details, if I get a good practical way to achieve the needful.
However let us wait if someone else has a better idea to achieve the needful in an easier manner.
The native DISTANCE() function only measures straight lines. If you need actual driving/road distance, you must connect AppSheet to Google Apps Script using an automation.
Write a Google Apps Script using the Maps.newDirectionFinder() service to request directions between two addresses.
Have the script extract the route length and write it to your database.
Set up an AppSheet Automation (using the Call a Script task) to trigger this script automatically whenever new locations are saved.
Sure,
This is my expression, though i wonder if there’s a better way. It works for my case because I know there will only be a small, finite number of available properties . I’ve only indexed through 2 here to keep the example short
IF(CONTEXT(“ViewType”)=“Form”, “Distance to other available properties: “& IF(ISNOTBLANK(INDEX(SELECT(Available Properties[Property ID],[_THISROW].[Property]<>[Property ID]),1)),SELECT(Available Properties[Short Name],[Property ID]=INDEX(SELECT(Available Properties[Property ID],[_THISROW].[Property]<>[Property ID]),1)) &” (”& ROUND(DISTANCE(Any(SELECT(Available Properties[LatLong],[Property ID]=INDEX(SELECT(Available Properties[Property ID],[_THISROW].[Property]<>[Property ID]),1))),[Property].[LatLong]))&" km) “,”“)& IF(ISNOTBLANK(INDEX(SELECT(Available Properties[Property ID],[_THISROW].[Property]<>[Property ID]),2)),SELECT(Available Properties[Short Name],[Property ID]=INDEX(SELECT(Available Properties[Property ID],[_THISROW].[Property]<>[Property ID]),2)) &” (“& ROUND(DISTANCE(Any(SELECT(Available Properties[LatLong],[Property ID]=INDEX(SELECT(Available Properties[Property ID],[_THISROW].[Property]<>[Property ID]),2))),[Property].[LatLong]))&” km) “,”“) ,”")
Thank you @PGold. Got it. Great. It is what we call a brute force approach but works well for certain situations when there is no easy alternative.
Not sure at this moment if there is a better way. However the expression you shared could be possibly made shorter as follows. The sample below is also for 2 properties.
In terms of characters length the expression below has around 560 characters against 976 in the expression you shared, compressed to around 57 %
IFS(CONTEXT(“ViewType”)=“Form”, “Distance to other available properties:”)&"
"&IFS( ISNOTBLANK(INDEX(Available Properties[Property ID]-LIST([Property]),1)),