Skip to content

Instantly share code, notes, and snippets.

@jamiembrown
Created April 10, 2014 12:54
Show Gist options
  • Save jamiembrown/10379084 to your computer and use it in GitHub Desktop.
Save jamiembrown/10379084 to your computer and use it in GitHub Desktop.
Create a square around a latitude and longitude based on a distance in meters in PHP
$distance = 30000;
$radius_of_earth = 6335000;
$longitude_offset = ($distance / $radius_of_earth) * (180 / pi()) / cos(($latitude * pi())/180);
$latitude_offset = ($distance / $radius_of_earth) * (180 / pi());
$max_longitude = $longitude + $longitude_offset;
$min_longitude = $longitude - $longitude_offset;
$max_latitude = $latitude + $latitude_offset;
$min_latitude = $latitude - $latitude_offset;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment