http://www.perlmonks.org?node_id=866691


in reply to Re: Alternatives To Geo::Distance
in thread Alternatives To Geo::Distance

gray,
...he probably will accept patches via

I have emailed the author. I would like to offer a patch but I am not sure what the problem is. I was in a hurry to get my project complete so I could go to sleep.

A good reason to use Geo::Distance::XS

First, thanks! I admit that I didn't try it for a few reasons. The first is that I assumed one was just an XS implementation of the other to include the bug. The second reason is that in the environment where this needed to run, XS is not an easy option. Without going into a lot of detail - local politics have created technical hurdles I didn't want to jump through (I was tired). It is also the reason I didn't use GIS::Distance. I was pretty sure (and you confirmed) that it produces correct results but the litany of dependencies without an internet connection was unreasonable.

I am happy that there are working solutions out there. I guess after reflecting on my lamentation, what I really should have asked is: Does anyone know of a Geo::Distance::Lite that works?

Regarding your benchmark. First, I suspect you didn't "You can stick with the pure Perl version by setting the GEO_DISTANCE_PP environment variable before using this module" This is because Geo::Distance gave the correct answer which it I know it doesn't (the point of this thread). Second, it would only be fair to add tye's version which avoids the whole OO overhead.

Cheers - L~R

Replies are listed 'Best First'.
Re^3: Alternatives To Geo::Distance
by gray (Beadle) on Oct 22, 2010 at 02:32 UTC
    Regarding your benchmark. First, I suspect you didn't "You can stick with the pure Perl version by setting the GEO_DISTANCE_PP environment variable before using this module" This is because Geo::Distance gave the correct answer which it I know it doesn't (the point of this thread).

    $ENV{GEO_DISTANCE_PP} just triggers Geo::Distance::XS->unimport(), which my benchmark script calls directly. I also checked the results by hiding Geo::Distance::XS with Test-Without-Module and they were consistent. Note also the results for the 'gcd' formula- both Geo::Distance and GIS::Distance::Fast failed, whereas Geo::Distance::XS produced a reasonable result. Perhaps if you posted your test script we could dig further.

      gray,
      Perhaps if you posted your test script we could dig further.

      Without Geo::Distance::XS present.

      #!/usr/bin/perl use strict; use warnings; use Geo::Distance; my $geo = Geo::Distance->new; for (qw/tv hsin polar cos gcd mt/) { $geo->formula($_); print $_, " ", $geo->distance('mile', 39.175555,-76.671388 => 33.9 +42222,-118.407222), "\n"; } __DATA__ tv 9537.71241222878 hsin 2881.23714304656 polar 3114.47526297555 cos 2881.23714304656 gcd 12438.0476860875-9076.08896733252i mt 2881.23714304656

      Geo::Distance::XS
      use strict; use warnings; use Geo::Distance::XS; my $geo = Geo::Distance->new; for (qw/tv hsin polar cos gcd mt/) { $geo->formula($_); print $_, " ", $geo->distance('mile', 39.175555,-76.671388 => 33.9 +42222,-118.407222), "\n"; } __DATA__ tv 9538.66771882495 hsin 2881.23714304656 polar 3114.47526297555 cos 2881.23714304656 gcd 2881.23714304656 mt 2881.23714304656
      Update: Ok, I am a freaking idiot who should not write code while up late at night. 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

        The module takes "long, lat"?! Well, I wouldn't call you the idiot. ;)

        A Google fight shows:

        • "lat long": 5.6 million hits
        • "long lat": 0.36 million hits

        And the first page of hits for "long lat" all have titles that include "latitude longitude" in that order.

        On such an interface, I'd probably require the tagging of the passed-in data with 'N' and 'E' to help avoid reversing the two numbers or getting a sign wrong.

        - tye