Skip to content

Instantly share code, notes, and snippets.

@joaofig
Created November 29, 2024 12:26
Show Gist options
  • Select an option

  • Save joaofig/0de0b4733eed9e79607feeeaf95bc0c1 to your computer and use it in GitHub Desktop.

Select an option

Save joaofig/0de0b4733eed9e79607feeeaf95bc0c1 to your computer and use it in GitHub Desktop.

Revisions

  1. joaofig created this gist Nov 29, 2024.
    24 changes: 24 additions & 0 deletions delta_location.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    def delta_location(lat: float,
    lon: float,
    bearing: float,
    meters: float) -> Tuple[float, float]:
    """
    Calculates a destination location from a starting location, a bearing and a
    distance in meters.
    :param lat: Start latitude
    :param lon: Start longitude
    :param bearing: Bearing (North is zero degrees, measured clockwise)
    :param meters: Distance to displace from the starting point
    :return: Tuple with the new latitude and longitude
    """
    delta = meters / 6378137.0
    theta = math.radians(bearing)
    lat_r = math.radians(lat)
    lon_r = math.radians(lon)
    lat_r2 = math.asin(math.sin(lat_r) * math.cos(delta) + math.cos(lat_r) *
    math.sin(delta) * math.cos(theta))
    lon_r2 = lon_r + math.atan2(math.sin(theta) * math.sin(delta) *
    math.cos(lat_r),
    math.cos(delta) - math.sin(lat_r) *
    math.sin(lat_r2))
    return math.degrees(lat_r2), math.degrees(lon_r2)