{"id":12545,"date":"2014-02-17T08:24:37","date_gmt":"2014-02-17T14:24:37","guid":{"rendered":"http:\/\/bucktownbell.com\/?p=12545"},"modified":"2014-02-17T13:05:31","modified_gmt":"2014-02-17T19:05:31","slug":"calculating-distance-between-longitude-and-latitude-pairs","status":"publish","type":"post","link":"http:\/\/bucktownbell.com\/?p=12545","title":{"rendered":"Calculating distance between longitude and latitude pairs"},"content":{"rendered":"<p><span style=\"color: #993300;\"><strong>Problem<\/strong><\/span>: I need a simple way to calculate distance between two pairs of longitude and latitude coordinates.<\/p>\n<p>Apparently there are several ways of making this calculation.\u00a0 Since none of my calculations would exceed 15 miles I was able to use the flat earth calculation which is the simplest but inaccurate as distances increase between the two points according to <a href=\"http:\/\/en.wikipedia.org\/wiki\/Geographical_distance\">this wikipedia article<\/a>.\u00a0 Here&#8217;s a blurb about the flat-earth formula:<\/p>\n<blockquote>\n<h2>Flat-surface formula<\/h2>\n<p>A planar approximation for the surface of the earth may be useful over small distances. The accuracy of distance calculations using this approximation become increasingly inaccurate as:<\/p>\n<ul>\n<li>The separation between the points becomes greater;<\/li>\n<li>A point becomes closer to a geographic pole.<\/li>\n<\/ul>\n<\/blockquote>\n<p>There were a bunch of sites that came up with all the different formulae over this but I&#8217;m not launching a satellite or programming a guided missile. The following code came from <a href=\"http:\/\/www.perlmonks.org\/\">perlmonks<\/a> which is a very reputable reference for anything to do with programming in perl. Here is the subroutine I chose to use. Article was written in 2002.<\/p>\n<blockquote><p><span style=\"color: #003300;\"><code><br \/>\nuse Math::Trig<br \/>\nsub FlatEarth {<br \/>\nmy ($lat1, $long1, $lat2, $long2) = @_;<br \/>\nmy $r=3956; my $a = (pi\/2)- deg2rad($lat1);<br \/>\nmy $b = (pi\/2)- deg2rad($lat2)<br \/>\nmy $c = sqrt($a**2 + $b**2 - 2 * $a *$b *cos(deg2rad($long2)-deg2rad($long1)));<br \/>\nmy $dist = $c * $r; return $dist;<br \/>\n}<\/code><\/span><\/p><\/blockquote>\n<p>Via <a href=\"http:\/\/www.perlmonks.org\/?node_id=150054\">Finding the Distance between longitude and latitude pairs<\/a>.<\/p>\n<p>The above code seems to work.\u00a0 Most of the calculations I needed to do were under a mile.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem: I need a simple way to calculate distance between two pairs of longitude and latitude coordinates. Apparently there are several ways of making this calculation.\u00a0 Since none of my calculations would exceed 15 miles I was able to use &hellip; <a href=\"http:\/\/bucktownbell.com\/?p=12545\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64],"tags":[900,171,72],"class_list":["post-12545","post","type-post","status-publish","format-standard","hentry","category-problems","tag-gps","tag-perl","tag-problem-solved"],"_links":{"self":[{"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/posts\/12545","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12545"}],"version-history":[{"count":5,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/posts\/12545\/revisions"}],"predecessor-version":[{"id":12565,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/posts\/12545\/revisions\/12565"}],"wp:attachment":[{"href":"http:\/\/bucktownbell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12545"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}