<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: distance between two coordinates in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/distance-between-two-coordinates/m-p/290026#M107646</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The attached example shows three different approaches (arccosine, Haversine, Vincenty) for calculating the distance between two points based on latitude and longitude.&amp;nbsp; See script comments for possible issues with each.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And yes, if you have a lot of points, and want to calculate the values in the script, the resulting table is huge.&amp;nbsp; With a lot of points, you'll likely need to calculate distance in a chart, and make sure the chart doesn't have your full data set of points.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 29 Jul 2011 23:38:45 GMT</pubDate>
    <dc:creator>johnw</dc:creator>
    <dc:date>2011-07-29T23:38:45Z</dc:date>
    <item>
      <title>distance between two coordinates</title>
      <link>https://community.qlik.com/t5/QlikView/distance-between-two-coordinates/m-p/290023#M107643</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to calculate distance between two coordinates in a scatter chart (superimposed on google map).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rahul &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jul 2011 11:54:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/distance-between-two-coordinates/m-p/290023#M107643</guid>
      <dc:creator />
      <dc:date>2011-07-19T11:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: distance between two coordinates</title>
      <link>https://community.qlik.com/t5/QlikView/distance-between-two-coordinates/m-p/290024#M107644</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just did this the other day.&amp;nbsp; I doubt I set this up the best way but... it's something.&amp;nbsp; This gives you the distance in miles, if you read the macro it should be easy to figure out how to make it in kilometers.&amp;nbsp; Also note that if you have a ton of points, the TempDistance table is goign to be huge.&amp;nbsp; I haven't really figured out hte best way to use this, I usually just do something like select a to_city and then search for distance &amp;lt;=50 or something.&amp;nbsp; First you have to do something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TempDistance:&lt;/P&gt;&lt;P&gt;NOCONCATENATE LOAD DISTINCT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; city,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; city.latitude,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; city.longitude&lt;/P&gt;&lt;P&gt;RESIDENT CityGPS;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;JOIN (TempDistance) LOAD DISTINCT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; city as 'to_city',&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; city.latitude as 'to_latitude',&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; city.longitude as 'to_longitude'&lt;/P&gt;&lt;P&gt;RESIDENT CityGPS;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That join gives you all combinations that you need the distance from.&amp;nbsp; In my case, I wanted the distance from each city, to each city.&amp;nbsp; Then do something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Distance:&lt;/P&gt;&lt;P&gt;LOAD DISTINCT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; city,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; to_city,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; round(haversine(city.latitude,city.longitude,to_latitude,to_longitude),'.1') as 'distance'&lt;/P&gt;&lt;P&gt;RESIDENT TempDistance;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Add the two macros below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Function haversine(lat1,long1,lat2,long2)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pi=4*Atn(1)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;r = 6371 'radius of the earth or something&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;lat1 = lat1 * pi / 180&lt;/P&gt;&lt;P&gt;lat2 = lat2 * pi / 180&lt;/P&gt;&lt;P&gt;long1 = long1 * pi / 180&lt;/P&gt;&lt;P&gt;long2 = long2 * pi/180&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;dLat = (lat2 - lat1) '* (pi / 180)&lt;/P&gt;&lt;P&gt;dLon = (long2 - long1)' * (pi / 180)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a = (sin(dLat / 2) * sin(dLat / 2)) +&amp;nbsp; cos(lat1) * cos(lat2)* (sin(dLon / 2) * sin(dLon / 2))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c = 2 * atan2(sqr(a),sqr(1-a))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;d = r * c&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;d = d * .621371192 '.621371192 converts km to miles&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;haversine = d&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;end Function&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Function atan2(ys,xs)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; If xs &amp;lt;&amp;gt; 0 Then&lt;/P&gt;&lt;P&gt;&amp;nbsp; theta = Atn(ys / xs)&lt;/P&gt;&lt;P&gt;&amp;nbsp; If xs &amp;lt; 0 Then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; theta = theta + pi&lt;/P&gt;&lt;P&gt;&amp;nbsp; End If&lt;/P&gt;&lt;P&gt; Else&lt;/P&gt;&lt;P&gt;&amp;nbsp; If ys &amp;lt; 0 Then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; theta = 3 * pi / 2 '90&lt;/P&gt;&lt;P&gt;&amp;nbsp; Else&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; theta = pi / 2 '270&lt;/P&gt;&lt;P&gt;&amp;nbsp; End If&lt;/P&gt;&lt;P&gt; End If&lt;/P&gt;&lt;P&gt; atan2 = theta&lt;/P&gt;&lt;P&gt;End Function&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jul 2011 18:00:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/distance-between-two-coordinates/m-p/290024#M107644</guid>
      <dc:creator />
      <dc:date>2011-07-29T18:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: distance between two coordinates</title>
      <link>https://community.qlik.com/t5/QlikView/distance-between-two-coordinates/m-p/290025#M107645</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My previous post was so long I thought it was best I just add another one.&amp;nbsp; Let's say you want to group cities based on how far they are from certain cities, here's what I did (if you know a better way I'd love to hear it):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Metropolis:&lt;/P&gt;&lt;P&gt;NOCONCATENATE LOAD DISTINCT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; city,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(distance &amp;lt;=50,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(to_city = 'DALLAS','DFW',&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(to_city = 'HOUSTON','HOUSTON',&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(to_city = 'ODESSA','ODESSA',&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(to_city = 'MCALLEN','SOUTH TEXAS',&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(to_city = 'CORPUS CHRISTI', 'CORPUS',&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(to_city = 'UVALDE', 'SAN ANTONIO',&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(to_city = 'KILLEEN', 'AUSTIN/WACO'))))))),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(distance &amp;lt;=80 AND to_city = 'SAN ANGELO', 'CENTRAL TEXAS')) as 'metroplex'&lt;/P&gt;&lt;P&gt;RESIDENT Distance;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jul 2011 18:05:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/distance-between-two-coordinates/m-p/290025#M107645</guid>
      <dc:creator />
      <dc:date>2011-07-29T18:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: distance between two coordinates</title>
      <link>https://community.qlik.com/t5/QlikView/distance-between-two-coordinates/m-p/290026#M107646</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The attached example shows three different approaches (arccosine, Haversine, Vincenty) for calculating the distance between two points based on latitude and longitude.&amp;nbsp; See script comments for possible issues with each.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And yes, if you have a lot of points, and want to calculate the values in the script, the resulting table is huge.&amp;nbsp; With a lot of points, you'll likely need to calculate distance in a chart, and make sure the chart doesn't have your full data set of points.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jul 2011 23:38:45 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/distance-between-two-coordinates/m-p/290026#M107646</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2011-07-29T23:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: distance between two coordinates</title>
      <link>https://community.qlik.com/t5/QlikView/distance-between-two-coordinates/m-p/290027#M107647</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;John,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your solution is very creative.&amp;nbsp; I love it but what would you do if you had millions of locations points as opposed to 5?&amp;nbsp; you can't possibily pre-calculate that many.&amp;nbsp; Is there a solution where you can load data on the fly?&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See my post:&amp;nbsp; &lt;A _jive_internal="true" class="loading" href="https://community.qlik.com/message/284004#284004"&gt;http://community.qlik.com/message/284004#284004&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for you contribution to the community!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Nov 2012 01:03:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/distance-between-two-coordinates/m-p/290027#M107647</guid>
      <dc:creator />
      <dc:date>2012-11-22T01:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: distance between two coordinates</title>
      <link>https://community.qlik.com/t5/QlikView/distance-between-two-coordinates/m-p/290028#M107648</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi John,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;how can I adapt your suggestion/solution to my case?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have two completely different DBs. The first containing all info (Lat and Long enclosed) for the Pharmacies of Italy. The second containing all info (Lat and Long enclosed) of all Dental Offices of Italy. I need to know all Dental Offices closer to the Pharmacy region by region.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you please provide me a little example on what to do?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot in advance&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jun 2014 17:27:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/distance-between-two-coordinates/m-p/290028#M107648</guid>
      <dc:creator />
      <dc:date>2014-06-03T17:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: distance between two coordinates</title>
      <link>https://community.qlik.com/t5/QlikView/distance-between-two-coordinates/m-p/1906685#M1217940</link>
      <description>&lt;P&gt;Hello John,&lt;/P&gt;
&lt;P&gt;I don't know whether other got the result what they are looking for, but when I converted your QLIK VIEW app into QLIK Sense app and tried the formula for my dashboard app, it is giving the wrong result for me. I am finding distance between ZIP - 32344 and 32336 which comes to 28.7 Miles as per google map, please see link below:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.google.com/search?q=distance+between+32344+to+32336&amp;amp;ei=ikIzYuPuLq26qtsPjZuE-AM&amp;amp;ved=0ahUKEwjj2-fQqs32AhUtnWoFHY0NAT8Q4dUDCA0&amp;amp;uact=5&amp;amp;oq=distance+between+32344+to+32336&amp;amp;gs_lcp=Cgdnd3Mtd2l6EAM6BwgAEEcQsAM6CggAEEcQsAMQyQM6BQghEKABSgQIQRgASgQIRhgAUPAJWKchYPMsaAJwAXgAgAGRAYgB-QKSAQMxLjKYAQCgAQHIAQjAAQE&amp;amp;sclient=gws-wiz" target="_blank"&gt;https://www.google.com/search?q=distance+between+32344+to+32336&amp;amp;ei=ikIzYuPuLq26qtsPjZuE-AM&amp;amp;ved=0ahUKEwjj2-fQqs32AhUtnWoFHY0NAT8Q4dUDCA0&amp;amp;uact=5&amp;amp;oq=distance+between+32344+to+32336&amp;amp;gs_lcp=Cgdnd3Mtd2l6EAM6BwgAEEcQsAM6CggAEEcQsAMQyQM6BQghEKABSgQIQRgASgQIRhgAUPAJWKchYPMsaAJwAXgAgAGRAYgB-QKSAQMxLjKYAQCgAQHIAQjAAQE&amp;amp;sclient=gws-wiz&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;and same with you formula coming out to be 132.29 miles. Picture attached. Due to nature of my job I can not share the data.&lt;/P&gt;
&lt;P&gt;Please let me know if there is any issue.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Prem&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2022 16:47:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/distance-between-two-coordinates/m-p/1906685#M1217940</guid>
      <dc:creator>prem_1961</dc:creator>
      <dc:date>2022-03-17T16:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: distance between two coordinates</title>
      <link>https://community.qlik.com/t5/QlikView/distance-between-two-coordinates/m-p/1906688#M1217941</link>
      <description>&lt;P&gt;Hello John,&lt;/P&gt;
&lt;P&gt;Attaching data for your reference.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Prem&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2022 16:54:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/distance-between-two-coordinates/m-p/1906688#M1217941</guid>
      <dc:creator>prem_1961</dc:creator>
      <dc:date>2022-03-17T16:54:39Z</dc:date>
    </item>
  </channel>
</rss>

