這是我爲此做好的一個功能。它將一些小數點作爲參數,並使用偶數/奇數的隨機數檢查來使隨機化的陽性/陰性。
$latlon = randomLatLon(4);
print_r($latlon);
function randomLatLon($granularity) {
// $granularity = Number of decimal spaces.
$power = pow(10,$granularity); // Extended 10 to the power of $granularity.
// Generate the lat & lon (as absolutes) according to desired granularity.
$lat = rand(0,90 * $power)/$power;
$lon = rand(0,180 * $power)/$power;
// Check if a random number is even to randomly make the lat/lon negative.
if (rand(0,100) % 2 == 0) {
$lat = $lat * -1;
}
// Same for lon...
if (rand(0,100) % 2 == 0) {
$lon = $lon * -1;
}
return array(
"lat" => $lat,
"lon" => $lon,
);
}
看到這個答案:http://stackoverflow.com/a/1504655/782609 – kamituel
聽起來像是你想要做類似'地理guessing'東西的東西嗎? –
Fred - Nope在地圖上只需要隨機標記。 – AdrenalineJunky