# Posted By

VisionHive on 09/01/12

# Statistics

Viewed 327 times
Favorited by 1 user(s)

# Miles to Latitude and Miles to Longitude Converter

/ Published in: PHP  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.

Copy this code and paste it in your HTML
`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);}` Subscribe to comments