--- title: "NEAREST(LT, LN, TLT, TLN)" slug: "distance" updated: 2022-09-23T19:15:54Z published: 2022-09-23T19:15:55Z canonical: "docs.datajet.app/distance" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.datajet.app/llms.txt > Use this file to discover all available pages before exploring further. # DISTANCE(A, B, C, D) ## Geo: DISTANCE(A, B, C, D) ### Calculates the distance of earth's surface, in meters, between pairs of coordinates (A,B) and (C,D) ## Purpose Use this function to: - Calculate the distance in meters between 2 sets of coordinates - Calculate the distance between points on a map ## Return Value | Property | Value | | --- | --- | | **FieldType** | Integer | | **FieldSize** | Short / Integer | | **DataType** | Discrete | | **DataSize** | Integer | ```shell Example Return Value: 0 to N, where N is the number of meters between points (A,B) and points (C,D) ``` ![Distance_Sample](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/Distance_Sample.PNG) ## Parameters | Parameter | JSON | Description | | --- | --- | --- | | **Table** | “targetTable”: “MyTableName” | The target table on which the new field will be created | | **Filter** | “dataset”: {DataSet_JSON} | Optional. If a filter is applied, records not in the filter DataSet will be returned as null. | | **Function** | "function":"geo" | Geo | | **Geo Function** | "p1": "DISTANCE(A, B, C, D)" | DISTANCE(A, B, C, D) | | **A** | “p2”: "lat_start" | Required. The field on the targetTable containing latitude for first pair of coordinates. *Supports:* - **DataType:** Discrete/Continuous - **Field Type:** Double - **Fixed Value:** #nn.nnnnnnn | | **B** | “p3”: "lon_start" | Required. The field on the targetTable containing longitude for first pair of coordinates. *Supports:* - **DataType: Discrete/Continuous** - **Field Type: Double** - **Fixed Value:** #nn.nnnnnnn | | **C** | “p4”: "lat_end" | Required. The field on the targetTable containing latitude for second pair of coordinates. *Supports:* - **DataType: Discrete/Continuous** - **Field Type: Double** - **Fixed Value:** #nn.nnnnnnn | | **D** | “p5”:"lon_end" | Required. The field on the targetTable containing longitude for second pair of coordinates. *Supports:* - **DataType: Discrete/Continuous** - **Field Type: Double** - **Fixed Value:** #nn.nnnnnnn | ## JSON Sample ```json { "method": "BuildBakedField", "project": "Model1", "targetTable": "BikeTripData", "overwrite": true, "name": "Distance", "function": "geo", "p1": "DISTANCE(A,B,C,D)", "p2": "lat_Start", "p3": "lon_Start", "p4": "lat_End", "p5": "lon_End" } ``` ## Usage Notes DISTANCE returns an integer value, representing the number of meters between the first and second set of coordinates. The method used is distance = Sqrt ( **(C - A)2 + (D - B)****2** ) See Also: - [Nearest(LT, LN, TLT, TLN)](/v1/docs/nearest) - DIST2NEAREST(LT, LN, TLT, TLN) - GMNearest, GMDIST2NEAREST - [Copy Up](/v1/docs/copy-up) - [Joins](/v1/docs/joins) ## Example | Example | Details | | --- | --- | | **Description** | Calculate straight-line distance between journey start point and end point | | **Input** | - Table: = [BikeTripData] - Function:= Geo - Filter: = [No Filter] - **Geo Function: = DISTANCE(A, B, C, D)** - A:= lat_Start - B:= lon_Start - C:= lat_End - D:= lon_End - Name: =Distance | | **Sample** | ![Distance_Example](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/Distance_Example.PNG) |