|Pathologically Eclectic Rubbish Lister|
Alternatives To Geo::Distanceby Limbic~Region (Chancellor)
|on Oct 21, 2010 at 18:07 UTC||Need Help??|
Limbic~Region has asked for the
wisdom of the Perl Monks concerning the following question:
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.
Cheers - L~R