Convert Miles To Latitude And Longtitude Using PHP
There are lots of functions out there that you can use to calculate the distance between two points, but what if you know one point and want to calculate the latitude or the longitude equivalent of a point’s fixed distance, in miles? Here’s a pretty neat and useful PHP snippet from VisionHive that does exactly just that.
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); }