# Python - fly to a waypoint given by GPS coordinates

**URL:** <https://discuss.px4.io/t/python-fly-to-a-waypoint-given-by-gps-coordinates/20622>\
**Category:** MAVSDK\
**Created:** [January 21, 2021, 4:19pm UTC](https://discuss.px4.io/t/python-fly-to-a-waypoint-given-by-gps-coordinates/20622 "2021-01-21T16:19:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![faris15](https://discuss.px4.io/user_avatar/discuss.px4.io/faris15/32/7346_2.png) [@faris15](https://discuss.px4.io/u/faris15)\
**Post date:** [January 21, 2021, 4:19pm UTC](https://discuss.px4.io/t/python-fly-to-a-waypoint-given-by-gps-coordinates/20622/1 "2021-01-21T16:19:36Z")

</div>

Is there a MAVSDK-Python example code to fly to a waypoint given by GPS coordinates ?

---

<div class="post-metadata">

**Author:** ![Katawan](https://discuss.px4.io/user_avatar/discuss.px4.io/katawan/32/5544_2.png) [@Katawan](https://discuss.px4.io/u/Katawan)\
**Post date:** [January 21, 2021, 4:34pm UTC](https://discuss.px4.io/t/python-fly-to-a-waypoint-given-by-gps-coordinates/20622/2 "2021-01-21T16:34:47Z")

</div>

Something like [this](https://github.com/mavlink/MAVSDK-Python/blob/main/examples/goto.py) ?

---

<div class="post-metadata">

**Author:** ![faris15](https://discuss.px4.io/user_avatar/discuss.px4.io/faris15/32/7346_2.png) [@faris15](https://discuss.px4.io/u/faris15)\
**Post date:** [January 21, 2021, 5:49pm UTC](https://discuss.px4.io/t/python-fly-to-a-waypoint-given-by-gps-coordinates/20622/3 "2021-01-21T17:49:45Z")

</div>

Yes, thanks a lot…

But this code makes the drone flying sideways not straight ahead, anyone have an idea to make the drone turn around and flight straight ahead ?

Like this image

 ![image](https://discuss.px4.io/uploads/default/original/2X/b/b41005bf77390b36174ee22bcc181b0454043f22.jpeg)

---

<div class="post-metadata">

**Author:** ![fulano](https://discuss.px4.io/user_avatar/discuss.px4.io/fulano/32/6206_2.png) [@fulano](https://discuss.px4.io/u/fulano)\
**Post date:** [January 21, 2021, 6:13pm UTC](https://discuss.px4.io/t/python-fly-to-a-waypoint-given-by-gps-coordinates/20622/4 "2021-01-21T18:13:48Z")

</div>

You can change [line 37](https://github.com/mavlink/MAVSDK-Python/blob/18636d74f7d6765e9f0f04c6ee5cd0852480184c/examples/goto.py#L37). The last parameter of the `goto_location()` method is the yaw angle, in degrees. Or you can add a new line before that first rotates the UAV and then _goto\_location_ as line 37.

---

<div class="post-metadata">

**Author:** ![faris15](https://discuss.px4.io/user_avatar/discuss.px4.io/faris15/32/7346_2.png) [@faris15](https://discuss.px4.io/u/faris15)\
**Post date:** [January 21, 2021, 6:21pm UTC](https://discuss.px4.io/t/python-fly-to-a-waypoint-given-by-gps-coordinates/20622/5 "2021-01-21T18:21:49Z")

</div>

@fulano  
Great, but is there an easy way to calculate the Yaw angle directly ?

---

<div class="post-metadata">

**Author:** ![faris15](https://discuss.px4.io/user_avatar/discuss.px4.io/faris15/32/7346_2.png) [@faris15](https://discuss.px4.io/u/faris15)\
**Post date:** [March 6, 2021, 7:19pm UTC](https://discuss.px4.io/t/python-fly-to-a-waypoint-given-by-gps-coordinates/20622/7 "2021-03-06T19:19:35Z")

</div>

I could do it using `latitude_deg` and `longitude_deg` from `drone.telemetry.position()`  
Thanks all

`async for position_info in drone.telemetry.position():`  
`current_latitude = position_info.latitude_deg`  
`current_longitude = position_info.longitude_deg`  
`break`

`yaw_angle = math.degrees(math.atan((destination_longitude - current_longitude) / (destination_latitude - current_latitude)))`

`if destination_latitude < current_latitude:`  
`yaw_angle += 180`

 ![image](https://discuss.px4.io/uploads/default/original/2X/a/a74655509912d0da36092035d1ee3536f9b41afe.jpeg)
