--- title: "NEAREST(LT, LN, TLT, TLN)" slug: "dist2nearest" updated: 2022-11-07T14:41:43Z published: 2022-11-07T14:41:43Z canonical: "docs.datajet.app/dist2nearest" --- > ## 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. # DIST2NEAREST(LT, LN, TLT, TLN) ## Geo: DIST2NEAREST (LT, LN, TLT, TLN) ### Returns the distance, in meters, from (LT,LN) to the nearest location, as found in lookup fields (TLT, TLN) ## Purpose Use this function to: - Calculate the distance between a geographical location and its nearest location in a lookup table - Find the distance between a geographical point and another location, where the location search has a minimum range to search above ## Return Value | Property | Value | | --- | --- | | **FieldType** | Integer | | **FieldSize** | Continuous | | **DataType** | Continuous | | **DataSize** | Integer | ```shell Example Return Value: 0 to N, where: - N is the number of meters between points (LT, LN) and points (TLT, TLN) - N is greater than the value provided by limiter ``` ![DistanceToNearest_Sample](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/DistanceToNearest_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": "DIST2NEAREST(LT,LN,TLT,TLN)" | DIST2NEAREST(LT,LN,TLT,TLN) | | **LT** | “p2”: "lat" | Required. The field on the targetTable containing the latitude value. *Supports:* - **DataType:** Discrete/Continuous - **Field Type:** Double - **Fixed Value:** #nn.nnnnnnn | | **LN** | “p3”: "lon" | Required. The field on the targetTable containing the longitude value *Supports:* - **DataType: Discrete/Continuous** - **Field Type: Double** - **Fixed Value:**#nn.nnnnnnn | | **TLT** | “p4”: "lat" | Required. The **fully qualified** column on the lookup table that contains latitude. Can be on a lookup table or on the targetTable. *Supports:* - **DataType: Discrete/Continuous** - **Field Type: Double** - **Fixed Value:**#nn.nnnnnnn | | **TLN** | “p5”:"lon" | Required. The **fully qualified** column on the lookup table that contains longitude. Can be on a lookup table or on the targetTable. *Supports:* - **DataType: Discrete/Continuous** - **Field Type: Double** - **Fixed Value:**#nn.nnnnnnn | | **Limiter** | “limiter”:"#1" | Optional. The column or value that provides a minimum threshold - values below the threshold will be excluded. Note that fixed values represent meters. *Supports:* - **DataType: Discrete/Continuous** - **Field Type: Double** - **Fixed Value:**#nn.nnnnnnn | ## JSON Sample ```json { "method": "BuildBakedField", "project": "Matching1", "targetTable": "worldcities", "overwrite": true, "name": "Distance To Nearest City", "function": "geo", "p1": "DIST2NEAREST(LT,LN,TLT,TLN)", "p2": "lat", "p3": "lng", "p4": "worldcities.lat", "p5": "worldcities.lng", "limiter": "#1" } ``` ## Usage Notes DIST2NEAREST returns an integer value representing the number of meters between the 2 points. Nearest points which are below the threshold specified by "limiter" will be excluded. For more information on using Geo functions, see [QQ - How do I get the name of the nearest city from a table of Geo Data?](/v1/docs/qq-how-do-i-get-the-name-of-the-nearest-city-from-a-table-of-geo-data) See Also: - [DISTANCE(A, B, C, D)](/v1/docs/distance) - [NEAREST(LT, LN, TLT, TLN)](/v1/docs/nearest) - [Copy Up](/v1/docs/copy-up) - [Joins](/v1/docs/joins) ## Example | Example | Details | | --- | --- | | **Description** | Find distance to nearest city in meters | | **Input** | - Table: = [worldcities] - Function:= Geo - Filter: = [No Filter] - **Geo Function: = "DIST2NEAREST(LT,LN,TLT,TLN)** - LT:= lat - LN:= lon - TLT:= worldcities.lat - TLN:= worldcities.lon - Limiter:=#1 - Name: =Distance to Nearest City | | **Sample** | ![DistanceToNearest_Example](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/DistanceToNearest_Example.PNG) |