谷歌地图API使用Math.random获取随机位置 - JS
Google Maps Api using Math.random to get random location - JS
我无法让我的地图转到随机位置。我希望它转到边界之间的随机位置(纬度 -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);
}
var random = new google.maps.LatLng( (Math.random()*(85*2)-85), (Math.random()*(180*2)-180) );
尝试这样的东西,或更一般地说:
function randomBetween(min, max) {
if (min < 0) {
return min + Math.random() * (Math.abs(min)+max);
}else {
return min + Math.random() * max;
}}
相关文章:
- 如何克隆图像并将其放置在随机位置
- 开玩笑:测试数组的随机位置
- 谷歌地图API使用Math.random获取随机位置 - JS
- 返回包含随机位置元素的数组
- 在随机位置与空格匹配字符串
- 如何使气泡图随机位置
- 启动HTML5<音频>在随机位置
- 使用jQuery将文本按字面顺序分解到随机位置
- 在HTML5蛇游戏中为食物生成随机位置时发生未捕获的TypeError
- 将图像定位在随机位置
- 如何对齐一个旋转的轮子停止在中心位置,而不是使用javascript随机位置
- 在Safari iOS10中,在iframe中调用element.focus()将父页面滚动到随机位置
- 使用javaScript在随机位置显示图像时遇到麻烦
- 如何让我的缩略图显示在随机位置(在存档页面wordpress)
- 附加内容的随机位置与jQuery
- 具有随机位置的数组
- 我如何在js中分散随机位置的图像
- 将字符串插入到另一个字符串中的随机位置
- 图像的随机位置
- 工具提示显示在随机位置