Trouble with passing XY coordinates Collector via Arcade Expression

785
6
09-01-2020 08:12 AM
AdamBourque
New Contributor III

Hello all, I was very excited to see this update that Collector supports Arcade expressions. I am trying to pass the existing feature service coordinates to the survey feature service layer using this article How To: Launch and populate a Survey123 for ArcGIS survey from Collector for ArcGIS using XY coordin... 

I still pass the Facility ID value through the popup which works 

arcgis-survey123://?itemID=82f592fb0cf2454f93a757705b3d50dc&field:FacilityID={FACILITYID}{expression/expr0}

but the location won't pass to my survey with this arcade expression implemented on AGOL feature layer: (it works during the "test" button but does not pass the values.

function MetersToLatLon(x, y) {
// Converts XY point from Spherical Mercator EPSG:3857(Web Mercator Auxiliary Sphere) to lat/lon in WGS84 Datum (EPSG:4326).
// Source: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
var originShift = 2.0 * PI * 6378137.0 / 2.0;

var lon = (x / originShift) * 180.0;
var lat = (y / originShift) * 180.0;

lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
return [lat, lon];
}
function CreateURLSurvey(lat, lon) {
var url = "&center=" + lat + "," + lon;// This is the line that defines the location
Console(url);
return url;
}

var latlon = MetersToLatLon(Geometry($feature).X, Geometry($feature).Y);
var url = CreateURLSurvey(latlon[0], latlon[1]);
return url;

 

Furthermore, do I need a geopoint field in the survey? (I've tried both and still no success, unless there's something specific in calculcation or something I am missing). 

Thank you all! 

0 Kudos
6 Replies
XanderBakker
Esri Esteemed Contributor

Hi Adam Bourque ,

I would probably suggest a couple of things to see where things fail. Is there a url created or does it just fail.Is there a way to see what the complete url is at this moment?

The expression currently is returning the part of the url including "&center". What happens when you take that part out and hardcode that on the URL after {FACILITYID}? What if you simple return the coordinates (before transforming them from Web Mercator into WGS1984), like this:

return Geometry($feature).Y + "," + Geometry($feature).X

Does it generate a URL at all?

What if you return some dummy WGS1984 coordinates. Does that work? The idea is to validate where this is going wrong.

Another option would be to explore ArcGIS Field Maps, which is currently in beta but is supposed to have better support for Arcade.

0 Kudos
AdamBourque
New Contributor III

Hi Xander, I tried your suggestion and hit "test" end up giving the wrong coordinates, or not in WGS1984 anyways which I would like to keep. 

Anyways, the arcade expression generates the correct coordinates (assuming &center= is valid) ; however, it does not automatically generate those coordinates for the Survey submission, instead it uses my current location. 

The survey successfully works via URL incorporated in the pop-up rather than using Arcade expression, but the Arcade expression fails to pass the latitude/longitude even though the "Test" works. I have tried on both COLLECTOR and AGOL 

Appreciate the attempted help Xander Bakker

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Adam Bourque ,

So, if I understand this correctly, the initial expression does create the correct URL including the correct coordinates, but Survey123 rejects those and uses the GPS location. Is that the case?

0 Kudos
KerryKang
Occasional Contributor II

@XanderBakker 

Hi, 

I have the same issue. I could create a correct url but Survey123 picks up GPS location. I hope to utilize this during offline mode especially using Field Maps' offline area rather than preparing tile map packages.

 

Kerry

 

0 Kudos
BHeist
by
New Contributor III

Has there been any updates to this? A possible solution to get it work and pass along the XY to the Survey using Arcade? 

I was able to get it to work by using a Custom Attribute Display but not with an Arcade Expression. 

0 Kudos
DavidBuehler
Occasional Contributor III

@XanderBakker

I used expression mentioned at the top of this post (https://support.esri.com/en/technical-article/000020624).  I am using at 3.12+ Survey, and a webmap in AGOL, it pushes over the the geometry, but it does not push over any other field.  It leaves that as the the {} example &field:FacilityID={FacilityID}  leaves the field filled with {FacilityID}.

 

Thoughts?

0 Kudos