/ 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.
Expand |
Embed | Plain Text
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). } 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); }
URL: http://www.visionhive.com