maheshkumar has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys, is there any way that I can find the distance between two cities or countries if i have the longitide and latitude of the place? Is there any such module present? Or is this even possible through Perl? Cheers
  • Comment on Finding distance between cities or countries Perl module

Replies are listed 'Best First'.
Re: Finding distance between cities or countries Perl module
by Khen1950fx (Canon) on Aug 16, 2012 at 12:18 UTC
    See: Geo::Distance::XS.
    #!/usr/bin/perl use strict; use autodie; use warnings; use Geo::Distance::XS; my $geo = Geo::Distance->new; my $distance = $geo->distance(mile => $lon1, $lat1 => $lon2, $lat2); print $distance;
Re: Finding distance between cities or countries Perl module
by not_japh (Novice) on Aug 16, 2012 at 12:13 UTC
    Give this a shot.
    use Math::Trig qw(great_circle_distance deg2rad rad2deg); sub NESW { Math::Trig::deg2rad($_[0]), Math::Trig::deg2rad(90 - $_[1]) } sub distance { my ($lat1, $lon1, $lat2, $lon2) = @_; my @src = NESW($lon1, $lat1); my @dest = NESW($lon2, $lat2); great_circle_distance(@src, @dest, 6378); } sub bearing { my ($lat1, $lon1, $lat2, $lon2) = @_; my @src = NESW($lon1, $lat1); my @dest = NESW($lon2, $lat2); rad2deg(Math::Trig::great_circle_direction(@src, @dest)); }
      Does this use greater circle line distance