Geovisualization Developer's Guide

proximity

When you use this function in a query, it calculates an approximate distance in kilometers between two geographical points given in latitude and longitude.

The output can be used in filters; for example, to filter out points that are inside or outside of a specific region.

The rule takes the following form:

proximity(lat1,lon1,lat2,lon2)

Where lat1, lon1 and lat2, lon2 represent the coordinates of the two points the distance between which is to be calculated. The returned value is a float giving an approximate distance between the points in kilometers.

For more information on using query functions and operators in a REST API request, see Queries. For an end-to-end description of how to create a query, see Creating a Query.

The example query below returns data points sorted by distance from a position sent in the URL parameters. This could be used, for example, to filter points of interest in a given radius from your current location.

{
  "dataset": "{DATASET_ID}",
  "metrics": [
    "Lat",
    "Lon",
    "distance"
  ],
    "namespace": {
      "mylat": {
        "source": [{"$input": "lat_position"}]
      },
      "mylon": {
        "source": [{"$input": "lon_position"}]
      },
      "distance": {
        "source": [
          "mylat",
          "mylon",
          "Lat",
          "Lon"
        ],
        "apply": [
          {
            "fn": "proximity",
            "type": "transform"
          }
        ]
      }
    },
    "order": [
      {
        "distance": "asc"
      }
    ],
    "limit": 10
}

The HTTP request would take the following form:

https://datalens.api.here.com/v1/queries/{QUERY_ID}/data?lat_position=0&lon_position=0&app_id={YOUR_APP_ID}&app_code={YOUR_APP_CODE}

The response includes an HTTP status code and a JSON response body.

For more information on the HTTP status codes, see HTTP Status Codes.

For more information on the elements in the JSON structure in the response body, see Query.