Skip to content

Instantly share code, notes, and snippets.

@tobsn
Created April 24, 2014 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobsn/11258555 to your computer and use it in GitHub Desktop.
Save tobsn/11258555 to your computer and use it in GitHub Desktop.
get random geo location points within a radius
<?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