Search code examples
pythongeopy

Get New GPS with Known start GPS, bearing and distance in feet


I am brand new to Python in general and have a limited but aged knowledge of Javascript. I am trying to accomplish a small project using Python, but I have gotten stuck with my own comprehension.

I have a GPS coordinate in decimal degrees as a starting point (30.456025341663068, -86.41408883615411), a distance in feet (86 feet) from the start point to the expected endpoint and I have a bearing in degrees (0 to 360) from start point to endpoint. Given these values, I am attempting to simply return the GPS coordinate in decimal degrees of the endpoint.

I found one StackExchange post that appears to give me a viable option using GeoPy, but I'm simply getting lost in trying to implement it. Can someone assist with how to accomplish this? GeoPy is not a requirement for me, I just imported it based on the answer in the other StackExchange question:

calculating a gps coordinate given a point, bearing and distance


Solution

  • Perhaps you could do something like this:

    import geopy
    import geopy.distance
    
    lat = 30.456025341663068
    lon = -86.41408883615411
    distance_ft = 86
    bearing = 0
    
    start_point = geopy.Point(lat, lon)
    end_point = geopy.distance.geodesic(feet=distance_ft).destination(start_point, bearing)
    
    print(end_point.latitude, end_point.longitude)
    

    This should output something like:

    30.456261790886277 -86.41408883615411
    

    You can then also use the geodesic method to calculate the distance between the points:

    print(geopy.distance.geodesic(start_point, end_point).feet)
    

    And get something like:

    86.0000000020017