谷歌地图-信息窗口弹出随机标记每3秒
Google map - infowindow pop-up on random marker every 3 seconds
问题在这里。
- 我需要用多个标记制作一个谷歌地图。
- 每个标记都有一个不同内容的信息窗口。当你打开网站后3秒信息窗口弹出一个随机标记。
- 然后关闭,3秒后弹出信息窗口形成另一个随机标记,依此类推
- 信息窗口也需要自动显示,而不是点击标记
我需要什么才能做到这一点?
很简单。首先,您需要设置具有多个标记的地图,将所有这些标记存储在数组中,然后对它们使用setInterval
触发单击事件。
<div>
<div id="map" style="width: 500px; height: 400px;"></div>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
</div>
JS:
//Define markers attribute
var locations = [
[
"New Mermaid",
36.9079, -76.199,
1,
"Georgia Mason",
"",
"Norfolk Botanical Gardens, 6700 Azalea Garden Rd.",
"coming soon"],
[
"1950 Fish Dish",
36.87224, -76.29518,
2,
"Terry Cox-Joseph",
"Rowena's",
"758 W. 22nd Street in front of Rowena's",
"found"],
[
"A Rising Community",
36.95298, -76.25158,
3,
"Steven F. Morris",
"Judy Boone Realty",
"Norfolk City Library - Pretlow Branch, 9640 Granby St.",
"found"],
[
"A School Of Fish",
36.88909, -76.26055,
4,
"Steven F. Morris",
"Sandfiddler Pawn Shop",
"5429 Tidewater Dr.",
"found"],
[
"Aubrica the Mermaid (nee: Aubry Alexis)",
36.8618, -76.203,
5,
"Myke Irving/ Georgia Mason",
"USAVE Auto Rental",
"Virginia Auto Rental on Virginia Beach Blvd",
"found"]
]
//Set up map.
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
// center: new google.maps.LatLng(-33.92, 151.25),
center: new google.maps.LatLng(36.8857, -76.2599),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
var markers = [];
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
markers.push(marker); // Store the markers in an array.
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(locations[i][0], locations[i][6]);
infowindow.open(map, marker);
}
})(marker, i));
}
var i = 0;
setInterval(function () {
if (i == markers.length) i = 0;
google.maps.event.trigger(markers[i], 'click'); // Trigger click on marker after 3s
i++;
}, 3000);
Demo: http://jsfiddle.net/lotusgodkk/pGBZD/153///顺序顺序
Demo: http://jsfiddle.net/lotusgodkk/pGBZD/154///用于随机排序
相关文章:
- 显示5秒后隐藏潜水
- $(document).height()在刷新时随机化值(Safari 5.1.10)
- 使用当前日期生成随机id
- X秒后刷新select元素
- 从a-z中随机选择一个字母
- 如何每10.6秒从时间戳增加+1
- 如果30秒未单击,请应用CSS一次,将其删除,然后重新迭代
- RequireJ无法随机加载脚本
- 设置随机数,然后每5秒随机减少一次,直到达到0(javascript)
- 显示数字,然后每5秒随机更改一次(javascript)
- 背景图像旋转器.php + jQuery每4秒显示一次随机照片
- 在 JavaScript 中以 5 秒的间隔生成随机值
- 网页上每 1/10 秒随机单词一次
- jquery 添加“随机”内容以从当前时间开始每秒值
- 随机秒后更改方框颜色
- php随机消息将在20秒内淡出到下一条随机消息
- 随机背景图像每5秒
- 谷歌地图-信息窗口弹出随机标记每3秒
- 在javascript中随机在1到5秒之间执行一个函数
- JavaScript幻灯片显示,改变幻灯片每3秒,并开始在一个随机的图像