# Are there any APIs that find the shortest sea distance between two points, given the latitude and longitude?

Searching online turns up websites like this one, which can return the shortest over-water distance between two ports, but I'm looking for something more general. Are there APIs or datasets that would allow me to calculate the shortest over-water distance between two points, given the points' latitude and longitude?

From what I've read, this is non-trivial to implement using Google Maps and the Google Maps API.

There are free data sets available for distances between ports: www.nauticalcharts.noaa.gov or msi.nga.mil

Also you will find some providers that give you distances between ports depending on AIS data like marinetraffic.com.

If you look for an API that gives you the shortest path between two coordinates on sea, there is Aquaplot

Disclaimer: I am the co-founder of Aquaplot.

/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*::                                                                         :*/
/*::  This routine calculates the distance between two points (given the     :*/
/*::  latitude/longitude of those points). It is being used to calculate     :*/
/*::  the distance between two locations using GeoDataSource(TM) Products    :*/
/*::                                                                         :*/
/*::  Definitions:                                                           :*/
/*::    South latitudes are negative, east longitudes are positive           :*/
/*::                                                                         :*/
/*::  Passed to function:                                                    :*/
/*::    lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees)  :*/
/*::    lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees)  :*/
/*::    unit = the unit you desire for results                               :*/
/*::           where: 'M' is statute miles (default)                         :*/
/*::                  'K' is kilometers                                      :*/
/*::                  'N' is nautical miles                                  :*/
/*::  Worldwide cities and other features databases with latitude longitude  :*/
/*::  are available at http://www.geodatasource.com                          :*/
/*::                                                                         :*/
/*::                                                                         :*/
/*::  Official Web site: http://www.geodatasource.com                        :*/
/*::                                                                         :*/
/*::                                                                         :*/
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
function distance($lat1,$lon1, $lat2,$lon2, $unit) {$theta = $lon1 -$lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles =$dist * 60 * 1.1515;
$unit = strtoupper($unit);

if ($unit == "K") { return ($miles * 1.609344);
} else if ($unit == "N") { return ($miles * 0.8684);
} else {
return \$miles;
}
}

echo distance(32.9697, -96.80322, 29.46786, -98.53506, "M") . " Miles";
echo distance(32.9697, -96.80322, 29.46786, -98.53506, "K") . " Kilometers";
echo distance(32.9697, -96.80322, 29.46786, -98.53506, "N") . " Nautical Miles<br>";

• The distance between two points is different than the distance over water between two points. Jul 31, 2016 at 6:54
• In addition to not answering the question this is also incomplete (though one can easily find the missing deg2rad, rad2deg, and strtoupper; not all that accurate; and appears to be cut and paste from material that is copyright geodatasource.com Aug 1, 2016 at 1:08