{"id":2912,"date":"2022-05-26T10:06:55","date_gmt":"2022-05-26T09:06:55","guid":{"rendered":"https:\/\/www.ridgesolutions.ie\/?p=2912"},"modified":"2022-05-26T10:08:50","modified_gmt":"2022-05-26T09:08:50","slug":"code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude","status":"publish","type":"post","link":"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/","title":{"rendered":"Code to calculate heading \/ bearing from two GPS latitude and longitude Points"},"content":{"rendered":"<p>Example code to Estimate heading or course\u00a0 of travel or bearing given two GPS locations taken from a recorded path.<\/p>\n<p>A lot of GPS devices will report heading along with latitude and longitude, but what if you lust have a series of GPS locations recorded from a path, how can you estimate heading or course of travel at points along the path\u00a0 given two consecutive GPS locations from the path?<\/p>\n<p>Why might you want to know heading along a path?\u00a0 Well imagine you have a mobile computer vision application, the effect of the Sun&#8217;s illumination may have a large effect on your imaging, if you can calculate the <a href=\"https:\/\/www.ridgesolutions.ie\/index.php\/2020\/01\/14\/c-code-to-estimate-solar-azimuth-and-elevation-given-gps-position-and-time\/\">Sun&#8217;s position<\/a> in the sky during the recorded path, and also calculate the camera&#8217;s &#8220;heading&#8221; then you can estimate the effect that the Sun will have on your images, for example are they back-lit, front-lit, will long shadows be cast etc.<\/p>\n<p>The background to the calculation can be found <a href=\"https:\/\/www.movable-type.co.uk\/scripts\/latlong.html\">here <\/a>under the section called &#8216;bearing&#8217;.<\/p>\n<p>Note that the terms &#8216;heading&#8217;, &#8216;bearing&#8217; and &#8216;course&#8217; have subtly different meanings especially for vehicles that might drift or yaw like boats or aircraft, but here we use them interchangeably to refer to the movement of the GPS measurement center.\u00a0 As the points we choose are close together we don&#8217;t really have to worry about the difference between initial bearing and final bearing.<\/p>\n<p>Here is some code that will calculate heading from 2 locations.\u00a0 Pass in the latitude and longitude of both points, the order in which the points are passed will affect the calculated heading.\u00a0 The two points that you choose should be close together to get a good estimate of &#8216;instantaneous&#8217; heading, however if they are too close together the estimate may be noisy due to the positional accuracy limits of GPS, a distance of 100m to 200m could work well, experiment for your GPS device and path type.<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">#define _USE_MATH_DEFINES\r\n#include &lt;math.h&gt;\r\n#include \"calculate_gps_heading.h\"\r\n\r\n\/\/   Copyright 2022 Kevin Godden\r\n\/\/\r\n\/\/   Licensed under the Apache License, Version 2.0 (the \"License\");\r\n\/\/   you may not use this file except in compliance with the License.\r\n\/\/   You may obtain a copy of the License at\r\n\/\/\r\n\/\/       http:\/\/www.apache.org\/licenses\/LICENSE-2.0\r\n\/\/\r\n\/\/   Unless required by applicable law or agreed to in writing, software\r\n\/\/   distributed under the License is distributed on an \"AS IS\" BASIS,\r\n\/\/   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n\/\/   See the License for the specific language governing permissions and\r\n\/\/   limitations under the License.\r\n\r\nstatic inline double to_rad(double theta) {\r\n    return (theta * M_PI) \/ 180.0;\r\n}\r\n\r\nstatic inline double to_degrees(double theta) {\r\n    return (theta * 180.0) \/ M_PI;\r\n}\r\n\r\n\/\/\r\n\/\/ Calculate the heading in decimal degrees between 2 (preferably quite close) locations \r\n\/\/ (lat1, lon1) --&gt; First location\r\n\/\/ (lat2, lon2) --&gt; Second location\r\n\/\/\r\ndouble calculate_gps_heading(double lat1, double lon1, double lat2, double lon2) {\r\n    \/\/ Convert degrees to radians\r\n    lat1 = to_rad(lat1);\r\n    lon1 = to_rad(lon1);\r\n    lat2 = to_rad(lat2);\r\n    lon2 = to_rad(lon2);    \r\n        \r\n    double dlon = lon2 - lon1;\r\n    double X = cos(lat2) * sin(dlon);\r\n    double Y = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dlon);\r\n    \r\n    double heading = atan2(X,Y);\r\n    \r\n    \/\/ We want heading in degrees, not radians.\r\n    heading = to_degrees(heading);\r\n  \r\n    \/\/ We want a uniform heading of &gt;=0 and &lt;360\r\n    if (heading &lt; 0)\r\n        heading = 360.0 + heading;\r\n    \r\n    return heading;\r\n}<\/pre>\n<p>The code along with some tests can be found in <a href=\"https:\/\/github.com\/kgodden\/calculate_gps_heading\">this<\/a> Git repo.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Example code to Estimate heading or course\u00a0 of travel or bearing given two GPS locations taken from a recorded path. A lot of GPS devices will report heading along with latitude and longitude, but what if you lust have a series of GPS locations recorded from a path, how can you estimate heading or course [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[301],"tags":[],"class_list":["post-2912","post","type-post","status-publish","format-standard","hentry","category-by-kevin-godden"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Example code to Estimate heading or course of travel or bearing given two GPS locations taken from a recorded path. A lot of GPS devices will report heading along with latitude and longitude, but what if you lust have a series of GPS locations recorded from a path, how can you estimate heading or course\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Kevin Godden\"\/>\n\t<meta name=\"google-site-verification\" content=\"Kyj52YLp6GOPA44PVBffo9fjW8rgWHYYRF0ZYjfy6ss\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Systems and Embedded Software Engineering, Ireland. | Some thoughts of a busy Computer Engineer\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Code to calculate heading \/ bearing from two GPS latitude and longitude Points\" \/>\n\t\t<meta property=\"og:description\" content=\"Example code to Estimate heading or course of travel or bearing given two GPS locations taken from a recorded path. A lot of GPS devices will report heading along with latitude and longitude, but what if you lust have a series of GPS locations recorded from a path, how can you estimate heading or course\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2022-05-26T09:06:55+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2022-05-26T09:08:50+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Code to calculate heading \/ bearing from two GPS latitude and longitude Points\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Example code to Estimate heading or course of travel or bearing given two GPS locations taken from a recorded path. A lot of GPS devices will report heading along with latitude and longitude, but what if you lust have a series of GPS locations recorded from a path, how can you estimate heading or course\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2022\\\/05\\\/26\\\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\\\/#article\",\"name\":\"Code to calculate heading \\\/ bearing from two GPS latitude and longitude Points\",\"headline\":\"Code to calculate heading \\\/ bearing from two GPS latitude and longitude Points\",\"author\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/wp-content\\\/uploads\\\/2013\\\/09\\\/ridge_logo1.jpg\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#articleImage\",\"width\":400,\"height\":81},\"datePublished\":\"2022-05-26T10:06:55+00:00\",\"dateModified\":\"2022-05-26T10:08:50+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2022\\\/05\\\/26\\\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2022\\\/05\\\/26\\\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\\\/#webpage\"},\"articleSection\":\"By Ridge Solutions\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2022\\\/05\\\/26\\\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.ridgesolutions.ie\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/category\\\/by-kevin-godden\\\/#listItem\",\"name\":\"By Ridge Solutions\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/category\\\/by-kevin-godden\\\/#listItem\",\"position\":2,\"name\":\"By Ridge Solutions\",\"item\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/category\\\/by-kevin-godden\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2022\\\/05\\\/26\\\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\\\/#listItem\",\"name\":\"Code to calculate heading \\\/ bearing from two GPS latitude and longitude Points\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2022\\\/05\\\/26\\\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\\\/#listItem\",\"position\":3,\"name\":\"Code to calculate heading \\\/ bearing from two GPS latitude and longitude Points\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/category\\\/by-kevin-godden\\\/#listItem\",\"name\":\"By Ridge Solutions\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#organization\",\"name\":\"Ridge Solutions, Software Development and Software Engineering, Ireland.\",\"description\":\"Some thoughts of a busy Computer Engineer\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/wp-content\\\/uploads\\\/2013\\\/09\\\/ridge_logo1.jpg\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2022\\\/05\\\/26\\\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\\\/#organizationLogo\",\"width\":400,\"height\":81},\"image\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2022\\\/05\\\/26\\\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\\\/#organizationLogo\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/#author\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/\",\"name\":\"Kevin Godden\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2022\\\/05\\\/26\\\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d2833f41e59a25cf2a9741a05ec383bfdd278762a5e0798a90940e7ab0a107a2?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Kevin Godden\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2022\\\/05\\\/26\\\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\\\/#webpage\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2022\\\/05\\\/26\\\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\\\/\",\"name\":\"Code to calculate heading \\\/ bearing from two GPS latitude and longitude Points\",\"description\":\"Example code to Estimate heading or course of travel or bearing given two GPS locations taken from a recorded path. A lot of GPS devices will report heading along with latitude and longitude, but what if you lust have a series of GPS locations recorded from a path, how can you estimate heading or course\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/2022\\\/05\\\/26\\\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/index.php\\\/author\\\/kgodden\\\/#author\"},\"datePublished\":\"2022-05-26T10:06:55+00:00\",\"dateModified\":\"2022-05-26T10:08:50+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#website\",\"url\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/\",\"name\":\"Ridge Solutions, Software Development and Software Engineering, Ireland.\",\"description\":\"Some thoughts of a busy Computer Engineer\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.ridgesolutions.ie\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Code to calculate heading \/ bearing from two GPS latitude and longitude Points","description":"Example code to Estimate heading or course of travel or bearing given two GPS locations taken from a recorded path. A lot of GPS devices will report heading along with latitude and longitude, but what if you lust have a series of GPS locations recorded from a path, how can you estimate heading or course","canonical_url":"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"google-site-verification":"Kyj52YLp6GOPA44PVBffo9fjW8rgWHYYRF0ZYjfy6ss","miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/#article","name":"Code to calculate heading \/ bearing from two GPS latitude and longitude Points","headline":"Code to calculate heading \/ bearing from two GPS latitude and longitude Points","author":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/#author"},"publisher":{"@id":"https:\/\/www.ridgesolutions.ie\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/www.ridgesolutions.ie\/wp-content\/uploads\/2013\/09\/ridge_logo1.jpg","@id":"https:\/\/www.ridgesolutions.ie\/#articleImage","width":400,"height":81},"datePublished":"2022-05-26T10:06:55+00:00","dateModified":"2022-05-26T10:08:50+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/#webpage"},"isPartOf":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/#webpage"},"articleSection":"By Ridge Solutions"},{"@type":"BreadcrumbList","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie#listItem","position":1,"name":"Home","item":"https:\/\/www.ridgesolutions.ie","nextItem":{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/by-kevin-godden\/#listItem","name":"By Ridge Solutions"}},{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/by-kevin-godden\/#listItem","position":2,"name":"By Ridge Solutions","item":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/by-kevin-godden\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/#listItem","name":"Code to calculate heading \/ bearing from two GPS latitude and longitude Points"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/#listItem","position":3,"name":"Code to calculate heading \/ bearing from two GPS latitude and longitude Points","previousItem":{"@type":"ListItem","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/by-kevin-godden\/#listItem","name":"By Ridge Solutions"}}]},{"@type":"Organization","@id":"https:\/\/www.ridgesolutions.ie\/#organization","name":"Ridge Solutions, Software Development and Software Engineering, Ireland.","description":"Some thoughts of a busy Computer Engineer","url":"https:\/\/www.ridgesolutions.ie\/","logo":{"@type":"ImageObject","url":"https:\/\/www.ridgesolutions.ie\/wp-content\/uploads\/2013\/09\/ridge_logo1.jpg","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/#organizationLogo","width":400,"height":81},"image":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/#organizationLogo"}},{"@type":"Person","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/#author","url":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/","name":"Kevin Godden","image":{"@type":"ImageObject","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/d2833f41e59a25cf2a9741a05ec383bfdd278762a5e0798a90940e7ab0a107a2?s=96&d=mm&r=g","width":96,"height":96,"caption":"Kevin Godden"}},{"@type":"WebPage","@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/#webpage","url":"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/","name":"Code to calculate heading \/ bearing from two GPS latitude and longitude Points","description":"Example code to Estimate heading or course of travel or bearing given two GPS locations taken from a recorded path. A lot of GPS devices will report heading along with latitude and longitude, but what if you lust have a series of GPS locations recorded from a path, how can you estimate heading or course","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.ridgesolutions.ie\/#website"},"breadcrumb":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/#breadcrumblist"},"author":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/#author"},"creator":{"@id":"https:\/\/www.ridgesolutions.ie\/index.php\/author\/kgodden\/#author"},"datePublished":"2022-05-26T10:06:55+00:00","dateModified":"2022-05-26T10:08:50+00:00"},{"@type":"WebSite","@id":"https:\/\/www.ridgesolutions.ie\/#website","url":"https:\/\/www.ridgesolutions.ie\/","name":"Ridge Solutions, Software Development and Software Engineering, Ireland.","description":"Some thoughts of a busy Computer Engineer","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.ridgesolutions.ie\/#organization"}}]},"og:locale":"en_US","og:site_name":"Systems and Embedded Software Engineering, Ireland. | Some thoughts of a busy Computer Engineer","og:type":"article","og:title":"Code to calculate heading \/ bearing from two GPS latitude and longitude Points","og:description":"Example code to Estimate heading or course of travel or bearing given two GPS locations taken from a recorded path. A lot of GPS devices will report heading along with latitude and longitude, but what if you lust have a series of GPS locations recorded from a path, how can you estimate heading or course","og:url":"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/","article:published_time":"2022-05-26T09:06:55+00:00","article:modified_time":"2022-05-26T09:08:50+00:00","twitter:card":"summary","twitter:title":"Code to calculate heading \/ bearing from two GPS latitude and longitude Points","twitter:description":"Example code to Estimate heading or course of travel or bearing given two GPS locations taken from a recorded path. A lot of GPS devices will report heading along with latitude and longitude, but what if you lust have a series of GPS locations recorded from a path, how can you estimate heading or course"},"aioseo_meta_data":{"post_id":"2912","title":null,"description":null,"keywords":[],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"aioseo-article-634e9df0bb2f1","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2022-05-26 08:42:17","updated":"2026-08-07 16:46:46","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.ridgesolutions.ie\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.ridgesolutions.ie\/index.php\/category\/by-kevin-godden\/\" title=\"By Ridge Solutions\">By Ridge Solutions<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tCode to calculate heading \/ bearing from two GPS latitude and longitude Points\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.ridgesolutions.ie"},{"label":"By Ridge Solutions","link":"https:\/\/www.ridgesolutions.ie\/index.php\/category\/by-kevin-godden\/"},{"label":"Code to calculate heading \/ bearing from two GPS latitude and longitude Points","link":"https:\/\/www.ridgesolutions.ie\/index.php\/2022\/05\/26\/code-to-calculate-heading-bearing-from-two-gps-latitude-and-longitude\/"}],"_links":{"self":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/posts\/2912","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/comments?post=2912"}],"version-history":[{"count":0,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/posts\/2912\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/media?parent=2912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/categories?post=2912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ridgesolutions.ie\/index.php\/wp-json\/wp\/v2\/tags?post=2912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}