<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Nearest Address Calculation Expression in Field Maps Smart Form in ArcGIS Field Maps Questions</title>
    <link>https://community.esri.com/t5/arcgis-field-maps-questions/nearest-address-calculation-expression-in-field/m-p/1188521#M3987</link>
    <description>&lt;P&gt;Hi Aaron,&lt;/P&gt;&lt;P&gt;Sorry for the late reply! I was able to figure out that the Web Map needed to have its projection changed by adding a service as a basemap with a different projection than web Mercator in order to match the layers' NAD 1983. I ended up using my original code based off the solution in the original post, but I had to reupload the hosted feature layers as Web Mercator.&lt;/P&gt;&lt;P&gt;Making sure everything in a workspace including the map is in the right projection is one of the most critical steps, but its something I wasn't familiar with in terms of ArcGIS Online jiminey crickets!!!&lt;/P&gt;&lt;P&gt;Thank you for your taking the time to make the solution!&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Oliver&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jun 2022 23:40:56 GMT</pubDate>
    <dc:creator>OliverSandoval_p</dc:creator>
    <dc:date>2022-06-30T23:40:56Z</dc:date>
    <item>
      <title>Nearest Address Calculation Expression in Field Maps Smart Form</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/nearest-address-calculation-expression-in-field/m-p/1176989#M3585</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am attempting to auto calculate a field in the Field maps smart form for a hosted feature layer using the new arcade calculation capability. Using the solution provided here&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-online-questions/using-arcade-to-find-the-nearest-address-point/m-p/108741#M5171" target="_blank" rel="noopener"&gt;Solved: Using Arcade to Find the Nearest Address Point - Esri Community&lt;/A&gt;&amp;nbsp;I kept getting wrong and inconsistent results for the nearest address. So I have now switched to making a dictionary and converting it into a feature so I can sort the buffer intersecting addresses by distance to get accurate results. Now I am just receiving null values&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Our feature services are in nad 1983.&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;Here is my code&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var search_distance = 150;
var addresses = FeatureSetById($map, /* AddressPoints_Export */ "AddressPoints_Export_5543")
var buf = Buffer($feature, search_distance, "feet")
var intersecting = Intersects(addresses, buf)
var cnt = Count(intersecting)
Console("Total Number of addresses within buffer: " + cnt)

var emptyDict = {
      'fields': [{ 'name': 'address', 'type': 'esriFieldTypeString'},{ 'name': 'distance_a', 'type': 'esriFieldTypeInteger'}],
      'geometryType': '',
      'features': []
};

var index = 0;
 if (cnt &amp;gt;0){  
    for (var f in intersecting){
        var addressDist = number(Distance(f,$feature, "feet"));
        var address_n = f.FULL_ADDRESS
        for(var i = 0; i &amp;lt;1; i++){
            emptyDict.features[index]= {
                'attributes':{
                        'address': address_n,
                        'distance_a': addressDist
                }
        }
    index++;    
        }
    }
}

var fs_dict = FeatureSet(Text(emptyDict));
var nearest_address = First(Orderby(fs_dict, 'distance_a DESC'));
return nearest_address;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;Any advice would be greatly appreciated!!&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;EDIT: I am able to view the dictionary successfully, but cant figure out how to sort and return it as a featureSet&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="console_results_dictionary.png" style="width: 852px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/42071i26376506B07254A5/image-size/large?v=v2&amp;amp;px=999" role="button" title="console_results_dictionary.png" alt="console_results_dictionary.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2022 20:04:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/nearest-address-calculation-expression-in-field/m-p/1176989#M3585</guid>
      <dc:creator>OliverSandoval_p</dc:creator>
      <dc:date>2022-05-24T20:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: Nearest Address Calculation Expression in Field Maps Smart Form</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/nearest-address-calculation-expression-in-field/m-p/1177996#M3660</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/509261"&gt;@OliverSandoval_p&lt;/a&gt;&amp;nbsp; Try something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// If feature doesn't have geometry return null
if (IsEmpty(Geometry($feature))) { return null }

// Get the parcels layer
var parcels = FeatureSetByName($map, 'Parcels')

// Buffer the current location and intersect with parcels
var bufferedLocation = Buffer($feature, 100, 'feet')
var candidateParcels = Intersects(parcels, bufferedLocation)

// Calculate the distance between the parcel and the current location
// Store the feature and distance as a dictionary and push it into an array
var featuresWithDistances = []
for (var f in candidateParcels) {
    Push(featuresWithDistances, 
        {
            'distance': Distance($feature, f, 'feet'),
            'feature': f
        }
    )
}

// Sort the candidate parcels by distance using a custom function
function sortByDistance(a, b) {
    return a['distance'] - b['distance']
}
var sorted = Sort(featuresWithDistances, sortByDistance)

// Get the closest feature
var closestFeatureWithDistance = First(sorted)

// If there was no feature, return null
if (IsEmpty(closestFeatureWithDistance)) { return null }

// Return the address
return `${closestFeatureWithDistance['feature']['ADDNUM']} ${closestFeatureWithDistance['feature']['ADDRESSNAM']}`&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think you were pretty close. You don't need to create a feature set, you can just create an array of objects and then use a custom sort function sort by distance, then access the attributes for that feature to generate the address.&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2022 15:37:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/nearest-address-calculation-expression-in-field/m-p/1177996#M3660</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-05-27T15:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: Nearest Address Calculation Expression in Field Maps Smart Form</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/nearest-address-calculation-expression-in-field/m-p/1188521#M3987</link>
      <description>&lt;P&gt;Hi Aaron,&lt;/P&gt;&lt;P&gt;Sorry for the late reply! I was able to figure out that the Web Map needed to have its projection changed by adding a service as a basemap with a different projection than web Mercator in order to match the layers' NAD 1983. I ended up using my original code based off the solution in the original post, but I had to reupload the hosted feature layers as Web Mercator.&lt;/P&gt;&lt;P&gt;Making sure everything in a workspace including the map is in the right projection is one of the most critical steps, but its something I wasn't familiar with in terms of ArcGIS Online jiminey crickets!!!&lt;/P&gt;&lt;P&gt;Thank you for your taking the time to make the solution!&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Oliver&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 23:40:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/nearest-address-calculation-expression-in-field/m-p/1188521#M3987</guid>
      <dc:creator>OliverSandoval_p</dc:creator>
      <dc:date>2022-06-30T23:40:56Z</dc:date>
    </item>
  </channel>
</rss>

