All,
Late last night, I had the task of determining the distance between two points identified by longitude and latitude in decimal degrees. I immediately installed
Geo::Distance because I clearly remember it being recommended here or on #perl (Freenode) anytime someone asks how to solve this problem. I wrote a simple test script and then went to google driving directions to verify. The distance from BWI airport to LAX was off by about 220 miles. Since roads are not straight (or great arcs), I knew they would not be exact. What surprised me though was that google actually showed the shorter distance. The module provides several methods for calculating distance but they were all off and some by even more.
After asking around what the problem might be, I had two possibilities. The first was that google better understood that the earth wasn't a perfect sphere and the other (thanks to tye) was that Geo::Distance was lousy at what it claimed to do. After doing some quick calculations by hand using the Great-circle_distance method, I agreed with tye.
In further reading the documentation, I realized I had missed the great big decommissioned sign which said new development should be done using GIS::Distance. I am pretty sure (but not positive) that it gave the correct response but after waiting for 10 minutes or more for it to install, I realized it was too heavy weight for something that should be fairly trivial.
I was able to get through my project, thanks in large part to tye sharing his quick implementation, but I am left wondering - what do other people use for this? Does the author know the values are so far off? I checked the open bug reports but I didn't see anything. Why should something that should be simple be so hard?
Update: I made a bonehead mistake and I am an idiot.I should not write code while up late at night and pressed for time. I swapped long/lat. This was further complicated by tye's method having in the same order as I was using which produces the correct result. I need to have my JAPH card revoked. Please forgive my gigantic stupidity.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.