How to Ensure The Distance between Two Locations Is within 5km

Hi :wave:

Today I would like to share with you how to ensure the distance between two locations is within 5km.

User is asked to record his/her location and the location his/her planned to visit.

Make sure the second location is within 5km radius of the first location.

Step & Configuration

  1. Create information

    • Information type - Location
      • location1
      • location2
    • Information type - Number
  2. To store more decimal places for latitude and longitude, select latitude1, open the advanced settings, type ‘5’ for the column of decimal places.
    (Repeat this step by replace latitude1 with longitude1, latitude2, and longitude2)
    **It is not necessary to change to 5 decimal places, you may set as your preferences.
    **If you prefer to have 2 decimal places, you can just skip this step.

  3. Configure a form for create
    i. Click ‘Start here’ in Basic.

    ii. Click ‘click to add’, then select the information created.

    iii. Set location1 and location2 as required field. (Mouse over the information name, then click the star button)

    iv. Set the formula for latitude1, longitude1, latitude2, and longitude2. (Mouse over the information name, then click the mathematics symbol. Then key in the formula, such as #Form#location1[‘lat’] for latitude1, and #Form#location1[‘lng’] for longitude1.)

    v. Hide the information distance (km) from the form. (To avoid the user key in the value.)

    vi. Click ‘SAVE’ after done. (To save the form.)

  4. Create an automation to calculate the distance between the 2 recorded location.
    i. Clicking the thunder icon to create new automation.

    ii. Toggle ‘Enable Advanced’.

    iii. Define the formula in the column of ‘Trigger Before Script’.

    iv. Click ‘OK’ after done.

  5. Then, click ‘SAVE’ at the top right of the module.

Sample Result
CPT2309081815-1264x545 (1)

:partying_face: Congratulations! You have done to define an automation to limit the distance between 2 location.

1 Like

Hi, just to confirm, is the trigger before script only with 23 lines? If more than 23 lines, please share here the full script here. Appricate, thanks.

Hi how to set Location 2 something like “Current Location”? Location 1 as fixed location? So that when user clock in always compare between current location, and fixed visit location? Thanks.

Hi, that is the full script.