Search code examples
iosmapsdirectionheading

Compute Heading iOS mapkit


I am working on functionality where I need to animate car driving on the map which is similar to what Uber has for customer application.

Current approach: I receive latest driver's coordinate from the api after particular polling interval, I use latest lat long and last known lat long to calculate directions using MKDirection. Currently I am able to animate car on this polyline received via directions api but I am not sure how to calculate heading to rotate car in a particular directions.

Note: Client's requirement is to use apple's native maps and api available and not to use Google Maps api.

Any insights on computing heading will be helpful.


Solution

  • Have you looked at this answer? https://stackoverflow.com/a/12696424/1364963

    This should outline how to calculate a heading from two GPS coordinates.