免责声明:您可以使用 vanilla Javascript 实现此目的。
由于您没有数据库,您可以使用LatLng class 的数组来指定要显示的坐标:
//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);
请找到工作示例here。
我希望这会有所帮助!