Javascript 我想通过循环或其他方式随机改变谷歌标记的位置

Javascript 我想通过循环或其他方式随机改变谷歌标记的位置,javascript,laravel,google-maps-markers,Javascript,Laravel,Google Maps Markers,我是新的谷歌API,我想在谷歌地图上自动改变谷歌标记的位置,五秒钟后它会自动改变地图上的位置。我没有纬度和经度的分贝。 我的意思是说标记在地图上随机改变它的位置 免责声明:您可以使用香草Javascript实现这一点 由于您没有数据库,因此可以使用的数组指定要显示的坐标: //an array of geographical coordinates var locations = [ new google.maps.LatLng(6.528166, 20.439864), /

我是新的谷歌API,我想在谷歌地图上自动改变谷歌标记的位置,五秒钟后它会自动改变地图上的位置。我没有纬度和经度的分贝。
我的意思是说标记在地图上随机改变它的位置

免责声明:您可以使用香草Javascript实现这一点

由于您没有数据库,因此可以使用的数组指定要显示的坐标:

  //an array of geographical coordinates
  var locations = [
      new google.maps.LatLng(6.528166, 20.439864), //somewhere in Africa
      new google.maps.LatLng(34.494890, 103.854720), //somewhere in China
      new google.maps.LatLng(51.802090, 7.771800), // somewhere in Germany
      new google.maps.LatLng(46.153450, -101.948783), // somewhere in US
      new google.maps.LatLng(-11.495951, -49.266451), // somewhere in Brazil
      new google.maps.LatLng(-80.287421, 23.599101) // somewhere in Antartica
  ];
之后,您可以使用
setInterval()
函数,该函数将包含将地理坐标数组中的项目随机化并更改地图和标记位置的代码

// set interval that will repeat every after 5 seconds
setInterval(function() {

    // pick random coordinates from the locations array
    var randomLocation = locations[Math.floor(Math.random() * locations.length)];

    // change the map center
    map.setCenter(randomLocation);

    // change the marker position
    marker.setPosition(randomLocation);
}, 5000);
请找到工作样品


我希望这有帮助

到目前为止你都尝试了什么?我的意思是说标记在5秒钟后随机改变它在地图上的位置