Created
April 24, 2014 15:20
-
-
Save tobsn/11258555 to your computer and use it in GitHub Desktop.
get random geo location points within a radius
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 | |
function getLocation( $y0, $x0, $rad ) { | |
$rad = $rad / 111195.0; | |
echo '$rad: '.$rad."\n"; | |
$u = (float)mt_rand() / (float)getrandmax(); | |
$v = (float)mt_rand() / (float)getrandmax(); | |
echo 'rand: '.$v.' '.$u."\n"; | |
$w = $rad * sqrt( $u ); | |
echo '$w: '.$w."\n"; | |
$t = 2 * pi() * $v; | |
echo '$t: '.$t."\n"; | |
$y = $w * sin( $t ); | |
echo '$y: '.$w."\n"; | |
$x = $w * cos( $t ); | |
echo '$x: '.$w."\n"; | |
$new_x = $x / cos( $y0 ); | |
echo '$new_x: '.$new_x."\n"; | |
return [ | |
'y' => number_format( ( $y + $y0 ), 7 ), | |
'x' => number_format( ( $new_x + $x0 ), 7 ) | |
]; | |
} | |
$x = getLocation( 19.9449799, 50.0646501, 12000 ); | |
echo '50.0646501 19.9449799'."\n"; | |
echo $x['x'].' '.$x['y']; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment