humbertovarona / perlCalcGeodist

Compute the distance between two geographic points (perl code)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

perlCalcGeodist

Compute the distance between two geographic points (perl code)

Version

Release date

License

Programming language

OS

Requirements

use strict;
use warnings;
use Math::Trig;

Function list

  1. calculate_distance Computes the distance between two points on the Earth's surface using the Haversine formula.

Arguments:

lat1: Latitude of the first point in degrees

lon1: Longitude of the first point in degrees

lat2: Latitude of the second point in degrees

lon2: Longitude of the second point in degrees

Returns: distance Distance between the two points in degrees

  1. convert_distance Converts the distance to the specified unit

Arguments:

distance: Distance to convert

unit: Unit of measurement to convert to ("km", "miles", or "nm")

Returns: Converted distance

Usage example

print "Enter the latitude of the first point: ";
my $lat1 = <STDIN>;
chomp($lat1);
print "Enter the longitude of the first point: ";
my $lon1 = <STDIN>;
chomp($lon1);
print "Enter the latitude of the second point: ";
my $lat2 = <STDIN>;
chomp($lat2);
print "Enter the longitude of the second point: ";
my $lon2 = <STDIN>;
chomp($lon2);

my $distance = calculate_distance($lat1, $lon1, $lat2, $lon2);

print "Enter the unit to convert to (km, miles, nautical miles): ";
my $unit = <STDIN>;
chomp($unit);
my $converted_distance = convert_distance($distance, $unit);

# Print the result on screen
printf "The distance between the two points is approximately %.2f %s.\n", $converted_distance, $unit;

About

Compute the distance between two geographic points (perl code)

License:MIT License


Languages

Language:Raku 100.0%