How to get a random lat long around my place so as not to go out of the border
Closed due to the fact that the essence of the issue is not clear by the participants user194374, Ksenia , Alex , Denis Bubnov , pavel December 1, '16 at 11:47 .
Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
- Where is the input data? What do you want to end up with? - fens
|
1 answer
$earthRadius = 6371000; $myLat=...; $myLng=...; $maxRadius=...; $angle=2 * M_PI * mt_rand(0, 1000) / 1000; $radius=mt_rand(0, $maxRadius); $north = sin($angle) * distance; $east = cos($angle) * distance; $newLat = $myLat + ($north / $earthRadius) * 180 / M_PI; $newLon = $myLng + ($east / ($earthRadius * cos($newLat * M_PI / 180))) * 180 / M_PI; |