Last active
August 29, 2015 14:01
-
-
Save safecat/d43818438cb6b20dc2e6 to your computer and use it in GitHub Desktop.
PHP Mercator Projection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//based on http://www.cnblogs.com/enjoyeclipse/archive/2013/01/18/2865700.html | |
function latlng2xy($lat, $lng, $zoom){ | |
if (abs($lat) > 85.0511287798066){ | |
return false; | |
} | |
$sin_phi = sin($lat * M_PI / 180); | |
$norm_x = $lng / 180; | |
$norm_y = (0.5 * log((1 + $sin_phi) / (1 - $sin_phi))) / M_PI; | |
$tileRow = pow(2, $zoom) * ((1 - $norm_y) / 2); | |
$tileColumn = pow(2, $zoom) * (($norm_x + 1) / 2); | |
return array( | |
'y'=>$tileRow, | |
'x'=>$tileColumn | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment