Miles to Latitude and Miles to Longitude Converter


/ Published in: PHP
Save to your folder(s)

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
  1. function M2LONG($m,$l)
  2. { // Returns the number of degrees of longitude equivalent to $m miles at latitude $l
  3. // (c) Peter Mugane Kionga-Kamau http://www.visionhive.com
  4. // Free for unrestricted use with this notice and description unaltered.
  5. // Note: The parameters and return values are in degrees, NOT RADIANS - because lat/long are generally measured in degrees.
  6. // Note: Assumes the earth is spherical with a circumference of 24,901.55 miles (calculation left here for clarity).
  7. return $m/(cos(deg2rad($l))*24901.55/360);
  8. }
  9. function M2LAT($m)
  10. { // Returns the number of degrees of latitude equivalent to $m miles
  11. // (c) Peter Mugane Kionga-Kamau http://www.visionhive.com
  12. // Free for unrestricted use with this notice and description unaltered.
  13. // Note: The parameters and return values are in degrees, NOT RADIANS - because lat/long are generally measured in degrees.
  14. // Note: Assumes the earth is spherical with a circumference of 24,901.55 miles (calculation left here for clarity).
  15. return $m/(24901.55/360);
  16. }

URL: http://www.visionhive.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.