When a new point is created in my editable layer, I want the lat/long in decimal degrees to auto-populate Latitude and Longitude fields (both double). The fields are not editable and show that they are calculated. But when I create a new point, these fields are not auto-populated. They just display "--". What are I doing wrong?
Using latitude as an example, these fields are calculated using the Arcade expression below taken from the Forum. When I tested the expression, it gave me the result I expected, latitude in decimal degrees.
Thanks for your help.
Dan
Solved! Go to Solution.
Chris, I think I solved the problem. As you suggested, just using Geometry($feature).x (or y) did work, which made me think that if I reduced the Arcade code I was using to a straight calculation maybe that would finish the job.
Here's what I created to auto-populate Lat and Long fields:
For latitude 57.2957795786 * (2.0 * Atan( Exp( (Geometry($feature).y * .00000898315285) * .0174532925)) - 1.570796325)
For longitude Geometry($feature).x * .00000898315285
The results auto-fill the fields with decimal degree coordinates that match what the phone GPS shows as the location of the new point.
I took all the arithmetic calculations in the original Arcade code and just replaced them with the number that resulted. This simplified the expressions a lot. Also, this reduces the multiple Arcade instructions I was using into a single calculated expression based solely on the Geometry functions which worked.
Thanks for your help.
Dan
Dan, my first guess would be that it does not have a GPS fix and cannot actually get a lat/long without this fix. Are you able to verify that there is a GPS fix and the device should be able to tell its location?
Adrian, when I click "+" to add a new point, go through the filter associated with the layer, and then select "Add point", the point's lat and long in decimal degrees appear at the top of the FM form, presumably from the phone's GPS chip. Right now, I'm having field workers copy that info into the Lat and Long fields in the FM form. But FM should be able to auto-fill those fields. When I get the Web Mercator coords for the point that FM uses and run the Arcade formula shown in the post, I get the same decimal degrees as shown at the top of the form from the phone's GPS. I just can't get the result to auto-populate the two fields in the layer.
Hi @DanGruber
The form should be able to calculate the geometry based on the location of a newly added point. One thing you could do to test is to just return Geometry($feature).y without all of the additional calculations and see if that works. If it does then you'll know the problem is somewhere in your arcade calculations. One thing you could try then is turn the conversion into a function, just to make the code a bit more clear.
Chris
Thanks, Chris, I'll try that. What does it mean to turn the conversion into a function?
Dan
Chris, when I tried simply using "Geometry($feature).x" (or ".y") as you suggested, the fields were auto-populated with the Web Mercator coordinates. So you were correct that the problem is in the rest of the Arcade expression. But do you see what's wrong with it?
You also suggested turning the conversion into a function. I don't know what that means or how to do it. Can you (or someone else in the community) provide more detail?
Thanks again for your help.
Dan
Chris, I think I solved the problem. As you suggested, just using Geometry($feature).x (or y) did work, which made me think that if I reduced the Arcade code I was using to a straight calculation maybe that would finish the job.
Here's what I created to auto-populate Lat and Long fields:
For latitude 57.2957795786 * (2.0 * Atan( Exp( (Geometry($feature).y * .00000898315285) * .0174532925)) - 1.570796325)
For longitude Geometry($feature).x * .00000898315285
The results auto-fill the fields with decimal degree coordinates that match what the phone GPS shows as the location of the new point.
I took all the arithmetic calculations in the original Arcade code and just replaced them with the number that resulted. This simplified the expressions a lot. Also, this reduces the multiple Arcade instructions I was using into a single calculated expression based solely on the Geometry functions which worked.
Thanks for your help.
Dan
Hi @DanGruber - I'm glad it worked! For future reference, this example is what I mean by turning it into a function: https://community.esri.com/t5/developers-questions/lat-long-unit-conversion-with-arcade/m-p/207272/h.... You can define the conversion as a function you can call later in your code, you just need to pass the Geometry($feature).x and Geometry($feature).y into the function and make sure the function returns the format that you want. It makes things a bit more readable and easier to work with if you need to debug any issues.
Chris