Auto populate region based on GPS

855
3
Jump to solution
05-02-2022 05:52 AM
OliverIshmael
Occasional Contributor

In a form I am developing users currently pick which region of the country they are in and I wonder if this could be pre-populated using the GPS.

The regions are quite large, so the GPS reading wouldn't need to be super accurate (assuming they are not close to a region border) so I am hoping it could be calculated quickly.

Can this be achieved in any way e.g. using calculated expressions?

 

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

@OliverIshmael  Yup, you can do this. Here's an example to get the name of the region the device location is currently in. It returns the first region that is intersected, otherwise it defaults to returning null.

 

// Intersect the current location with the Region layer in the map
var features = Intersects($feature, FeatureSetByName($map, 'Region'))

// If there's at least one intersecting region, 
// return the Name of the first one
if (Count(features) > 0) {
    return First(features)['Name']
}

 

View solution in original post

3 Replies
by Anonymous User
Not applicable

@OliverIshmael  Yup, you can do this. Here's an example to get the name of the region the device location is currently in. It returns the first region that is intersected, otherwise it defaults to returning null.

 

// Intersect the current location with the Region layer in the map
var features = Intersects($feature, FeatureSetByName($map, 'Region'))

// If there's at least one intersecting region, 
// return the Name of the first one
if (Count(features) > 0) {
    return First(features)['Name']
}

 

OliverIshmael
Occasional Contributor

When I test this calculated expression, it works correctly. However, when I try using it in the form it doesn't populate the field. Not sure why.

Ideally I need it to be the default value, but still give the user the option to edit it if it is incorrect. It appears that editing the field must be disabled for calculated expressions, so in this instance @Anonymous User perhaps its not viable?

by Anonymous User
Not applicable

However, when I try using it in the form it doesn't populate the field

Are you seeing this in the Field Maps app? If so, iOS or Android?

Calculations only work if the form element is non-editable. We're planning to make the editable property dynamic via Arcade as well. So you can have it calculate in some cases, and not in others.

0 Kudos