Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript GoogleMapsAPI使用Math.random获取随机位置-JS_Javascript_Google Maps - Fatal编程技术网

Javascript GoogleMapsAPI使用Math.random获取随机位置-JS

Javascript GoogleMapsAPI使用Math.random获取随机位置-JS,javascript,google-maps,Javascript,Google Maps,我很难让我的地图去一个随机的位置。我希望它去边界之间的一个随机位置(lat-85到85,lng-180到180)。每当单击按钮时,该功能将使地图变为灰色 function random(lat, lng){ var random = new google.maps.LatLng((Math.random()-85)*85+, (Math.random()-180)*180)); map.panTo(random); } 试试这样的东西, 或者更一般地说: function randomBetw

我很难让我的地图去一个随机的位置。我希望它去边界之间的一个随机位置(lat-85到85,lng-180到180)。每当单击按钮时,该功能将使地图变为灰色

function random(lat, lng){
var random = new google.maps.LatLng((Math.random()-85)*85+, (Math.random()-180)*180));
map.panTo(random);
}
试试这样的东西, 或者更一般地说:

function randomBetween(min, max) {
if (min < 0) {
    return min + Math.random() * (Math.abs(min)+max);
}else {
    return min + Math.random() * max;
}}
函数随机性(最小值、最大值){
如果(最小值<0){
返回min+Math.random()*(Math.abs(min)+max);
}否则{
返回min+Math.random()*max;
}}
function randomBetween(min, max) {
if (min < 0) {
    return min + Math.random() * (Math.abs(min)+max);
}else {
    return min + Math.random() * max;
}}