Validate record is within geographic area
This example uses the INVALID, LATITUDE, and LONGITUDE functions to keep records from being saved when their geometry isn't within the state of Colorado, a conveniently rectangular state. NOTE: The LATITUDE and LONGITUDE functions will only return values if a record's geometry type is set to Point
, and there is a location set. Unless you have enabled Lines and Polygons for your app, the Point
type will be the only available geometry type for records in the app.
function validateLocation() {
// The rough bounds of Colorado
var minLatitude = 36.985;
var maxLatitude = 40.979;
var minLongitude = -109.028;
var maxLongitude = -102.063;
// The latitude and longitude of the record
var lat = LATITUDE();
var lng = LONGITUDE();
if (!(lat <= maxLatitude && lat >= minLatitude && lng <= maxLongitude && lng >= minLongitude)) {
INVALID("It looks like this record isn't within the State of Colorado. Please adjust the record's location to be within Colorado.");
}
}
ON('validate-record', validateLocation);
Updated 11 months ago