带有多个信息窗口的Google地图
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带有多个信息窗口的Google地图相关的知识,希望对你有一定的参考价值。
<div id="gloveMap" style="height:400px;width:320px;display:block;"> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script> <script type="text/javascript"> function mapIt(){ var latlng = new google.maps.LatLng(36.728058, -108.218686); var myOptions = { zoom: 11, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP, } var map = new google.maps.Map(document.getElementById('gloveMap'), myOptions); setMarkers(map, places); } var places = [ ['Station 1', 36.732281, -108.211212], ['Station 2',36.764225,-108.148329], ['Station 3',36.738504,-108.229113], ['Station 4',36.723368,-108.168837], ['Station 5',36.75534,-108.197532], ['Station 6',36.734918,-108.249559], ['The Daily Times',36.730449,-108.206899], ]; var popUps = [ '<strong>Farmington Fire Station 1</strong><br />301 N. Auburn', '<strong>Farmington Fire Station 2</strong><br />3800 English Road', '<strong>Farmington Fire Station 3</strong><br />1401 W. Navajo', '<strong>Farmington Fire Station 4</strong><br />790 S. Hutton', '<strong>Farmington Fire Station 5</strong><br />609 E. 30th', '<strong>Farmington Fire Station 6</strong><br />3101 W. Main', '<strong>The Daily Times</strong><br />301 N. Allen' ] var infowindow; function setMarkers(map, locations) { for (var i = 0; i < places.length; i++) { var myLatLng = new google.maps.LatLng(locations[i][1], locations[i][2]); var marker = new google.maps.Marker({ position: myLatLng, map: map, title: locations[i][0], }); (function(i, marker) { google.maps.event.addListener(marker,'click',function() { if (!infowindow) { infowindow = new google.maps.InfoWindow(); } infowindow.setContent(popUps[i]); infowindow.open(map, marker); }); })(i, marker); } }; mapIt();
以上是关于带有多个信息窗口的Google地图的主要内容,如果未能解决你的问题,请参考以下文章
“未定义 Google”错误 - 尝试创建信息窗口 Google 地图
尝试使用通过EJS传递给客户端的数据绘制多个Google Map标记/信息窗口时,initMap()不是一个函数