<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://forums.garmin.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to obtain the distance between two Location objects</title><link>https://forums.garmin.com/developer/connect-iq/f/discussion/2798/how-to-obtain-the-distance-between-two-location-objects</link><description>Hello,
 I&amp;#39;ve been searching on the forum but I didn&amp;#39;t find the answer: can you help me on how to obtain the distance between two Location objects please?
 
 Thank you!
 Regards,
 
 Marc</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 04 Apr 2016 09:54:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://forums.garmin.com/developer/connect-iq/f/discussion/2798/how-to-obtain-the-distance-between-two-location-objects" /><item><title>RE: How to obtain the distance between two Location objects</title><link>https://forums.garmin.com/thread/19565?ContentTypeID=1</link><pubDate>Mon, 04 Apr 2016 09:54:47 GMT</pubDate><guid isPermaLink="false">a9571b57-dd57-479e-8763-8f8a603e40aa:2e81aa4e-6957-4a7a-80bd-b5e1657cdf1d</guid><dc:creator>MarkusGL</dc:creator><description>Thank you very much.
&lt;br /&gt;This is a good starting point :)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to obtain the distance between two Location objects</title><link>https://forums.garmin.com/thread/19507?ContentTypeID=1</link><pubDate>Fri, 01 Apr 2016 17:04:17 GMT</pubDate><guid isPermaLink="false">a9571b57-dd57-479e-8763-8f8a603e40aa:1c0d7e84-0802-44c0-93e4-6ab773c9c53d</guid><dc:creator>jim_m_58</dc:creator><description>Yes, the thread Travis linked to provides both methods.  I&amp;#39;ve been using the &amp;quot;planetscooter&amp;quot; method since then, but I changed it some parameter wise and this is it now:
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;//
&lt;br /&gt;	// distance between two location (meters) and returns formatted string
&lt;br /&gt;	//
&lt;br /&gt;	function computeDistance(lat1, lon1, lat2, lon2) {
&lt;br /&gt;		var mlat,mlon;
&lt;br /&gt;		var dx, dy, distance;
&lt;br /&gt;    
&lt;br /&gt;  		mlat = (lat1 + lat2) / 2 * 0.01745;
&lt;br /&gt;  		dx = 111.3 * Math.cos(mlat) * (lon1 - lon2); 
&lt;br /&gt;  		dy = 111.3 * (lat1 - lat2);
&lt;br /&gt;  		distance = 1000 * Math.sqrt(dx * dx + dy * dy);
&lt;br /&gt;  		return distToStr(distance);
&lt;br /&gt;	}
&lt;br /&gt;&lt;/code&gt;
&lt;br /&gt;
&lt;br /&gt;it isn&amp;#39;t exact for short distances (&amp;lt;300&amp;#39;), and some of that is the GPS locations can be a bit off, just by the nature of GPS.  &amp;quot;distToStr()&amp;quot; converts the meters into a string of meters or feet, km or miles, based on the watch&amp;#39;s setting for &amp;quot;distanceUnits&amp;quot;.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to obtain the distance between two Location objects</title><link>https://forums.garmin.com/thread/19499?ContentTypeID=1</link><pubDate>Fri, 01 Apr 2016 15:04:43 GMT</pubDate><guid isPermaLink="false">a9571b57-dd57-479e-8763-8f8a603e40aa:e69fcfb5-3c47-4f85-a041-2d8e32edeaea</guid><dc:creator>travis.vitek</dc:creator><description>If you know you&amp;#39;re only going to deal with points that are relatively close, you can use the pythagorean theorem. If you are potentially showing the distance between points very far away, you should consider using the haversine. This post has examples of both bits of code.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>