github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/doc/content/en/docs/javascript/geo.md (about)

     1  ---
     2  title: "Geography"
     3  linkTitle: "geography"
     4  date: 2023-10-05
     5  description: >
     6  
     7  ---
     8  
     9  These methods can be valuable when developing automated scenarios or applications in the "Smart Home" system where geographical aspects need to be considered, such as device locations, safety zones, or other geographic-related information.
    10  
    11  1. `GeoDistanceToArea(areaId, point)`: This method allows you to determine the distance between a specified point (`point`) and a geographical area identified by its identifier (`areaId`). Typically, it is used to determine how close a point is to a specific area.
    12  
    13  2. `GeoPointInsideArea(areaId, point)`: This method is used to check if a given point (`point`) is inside a geographical area identified by its identifier (`areaId`). It returns a boolean value (true/false) indicating whether the point belongs to the specified area.
    14  
    15  3. `GeoDistanceBetweenPoints(point1, point2)`: This method enables you to calculate the distance between two specified points (`point1` and `point2`). It is commonly used to measure the distance between two geographic coordinates, for example, to determine the distance between two devices or locations.
    16  
    17  
    18  
    19  1. Example of using `GeoDistanceToArea`:
    20  ```coffeescript
    21  # Determining the distance from point (55.7558, 37.6176) to the geographical area with the identifier "my_area."
    22  distance = GeoDistanceToArea("my_area", { latitude: 55.7558, longitude: 37.6176 })
    23  
    24  if distance < 1000
    25    console.log("The point is close to the geographical area.")
    26  else
    27    console.log("The point is far from the geographical area.")
    28  ```
    29  
    30  2. Example of using `GeoPointInsideArea`:
    31  
    32  ```coffeescript
    33  # Checking if the point (40.7128, -74.0060) is inside the geographical area with the identifier "nyc."
    34  isInside = GeoPointInsideArea("nyc", { latitude: 40.7128, longitude: -74.0060 })
    35  
    36  if isInside
    37    console.log("The point is inside New York.")
    38  else
    39    console.log("The point is outside New York.")
    40  ```
    41  
    42  3. Example of using `GeoDistanceBetweenPoints`:
    43  
    44  ```coffeescript
    45  # Calculating the distance between two points.
    46  point1 = { latitude: 34.0522, longitude: -118.2437 }
    47  point2 = { latitude: 37.7749, longitude: -122.4194 }
    48  
    49  distance = GeoDistanceBetweenPoints(point1, point2)
    50  
    51  console.log("Distance between points:", distance, "km")
    52  ```