-
Great circle distance
Great circle distance Find the distance in kilometres between two points on the surface of the earth. This is just the sort of problem stored functions were made for. For a first order approximation, ignore deviations of the earth's surface from the perfectly spherical. Then the distance in radians is given by a number of trigonometric formulas. ACOS and COS behave reasonably: COS(lat1-lat2)*(1+COS(lon1-lon2)) - COS(lat1+lat2)*(1-COS(lon1-lon2)) rads = ACOS( --------------------------------------------------------------------- ) 2 We need to convert degrees latitude and longitude to radians, and we need to know the length in km of one radian on the earth's surface, which is 6378.388. The function: set log_bin_trust_function_creators=TRUE; DROP FUNCTION IF EXISTS GeoDistKM; DELIMITER | CREATE FUNCTION GeoDistKM( lat1 FLOAT, lon1 FLOAT, lat2 FLOAT, lon2 FLOAT ) RETURNS float BEGIN DECLARE pi, q1, q2, q3 FLOAT; DECLARE rads FLOAT DEFAULT 0; SET pi = PI(); SET lat1 = lat1 * pi / 180; SET lon1 = lon1 * pi / 180; SET lat2 = lat2 * pi / 180; SET lon2 = lon2 * pi / 180; SET q1 = COS(lon1-lon2); SET q2 = COS(lat1-lat2); SET q3 = COS(lat1+lat2); SET rads = ACOS( 0.5*((1.0+q1)*q2 - (1.0-q1)*q3) ); RETURN 6378.388 * rads; END; | DELIMITER ; -- toronto to montreal (505km): select geodistkm(43.6667,-79.4167,45.5000,-73.5833); +----------------------------------------------+ | geodistkm(43.6667,-79.4167,45.5000,-73.5833) | +----------------------------------------------+ | 505.38836669921875 | +----------------------------------------------+
-
-
function distance($lat1, $lon1, $lat2, $lon2, $unit) {
-
$theta = $lon1 – $lon2;
-
$miles = $dist * 60 * 1.1515;
-
if ($unit == “K”) {
-
return ($miles * 1.609344);
-
} else if ($unit == “N”) {
-
return ($miles * 0.8684);
-
} else {
-
return $miles;
-
}
-
}
-
-
When the location you want is in the center of the map, copy and paste this code into the location bar of your browser and press enter
-
javascript:void(prompt(”,gApplication.getMap().getCenter()));
“longitude” related tags
spirit’s tags
access apache apache2 apt arguments auditd auth awk backup backups bandwidth bash bridge cache cd charset cisco commands conversion cron css date debian debug default diff directories directory distance dns dom du eth ethernet excel exclude files find firefox flash forms function hacks headers history hosts htaccess html http https ie ifconfig images input ip javascript jobs kill latitude linux log logging longitude mac mail maps merge monitoring mysql network nginx openssl packages performance performances perl php red hat regex restore root route rpm script security server shell ssh ssl svn switch syslog tail trunk unix virtualhost vlan vmware windows yum
-