Return to Snippet

Revision: 59348
at September 1, 2012 13:08 by VisionHive


Initial Code
function M2LONG($m,$l)
{	// Returns the number of degrees of longitude equivalent to $m miles at latitude $l
	// (c) Peter Mugane Kionga-Kamau http://www.visionhive.com
	// Free for unrestricted use with this notice and description unaltered.
	// Note: The parameters and return values are in degrees, NOT RADIANS - because lat/long are generally measured in degrees.
	// Note: Assumes the earth is spherical with a circumference of 24,901.55 miles (calculation left here for clarity).
	return $m/(cos(deg2rad($l))*24901.55/360);
}
function M2LAT($m)
{	// Returns the number of degrees of latitude equivalent to $m miles 
	// (c) Peter Mugane Kionga-Kamau http://www.visionhive.com
	// Free for unrestricted use with this notice and description unaltered.
	// Note: The parameters and return values are in degrees, NOT RADIANS - because lat/long are generally measured in degrees.
	// Note: Assumes the earth is spherical with a circumference of 24,901.55 miles (calculation left here for clarity).
	return $m/(24901.55/360);
}

Initial URL
http://www.visionhive.com

Initial Description
There are tons of functions out there to calculate the distance between two points, but what if you know one point and want to calculate the latitude ("vertical") or longitude ("horizontal") equivalent of a fixed distance, in miles? An example application would be in generating a minimum & maximum latitude and longitude bounding box around an area to limit the results of a database query that uses distance from a fixed point.

Initial Title
Miles to Latitude and Miles to Longitude Converter

Initial Tags


Initial Language
PHP