单击 Google Map API V3 时使用 infoWindow 或 InfoBox 触发事件 [英] Trigger event with infoWindow or InfoBox on click Google Map API V3
本文介绍了单击 Google Map API V3 时使用 infoWindow 或 InfoBox 触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何在使用 Google Maps API v3 单击信息窗口时触发事件.在这个例子中,当我点击一个标记时,一个信息窗口会根据我点击的标记显示一条独特的消息.我还希望能够单击信息窗口并显示一个警报,内容为
<块引用>您点击了信息窗口(__填写空白位置_)
我发现了一些使用 Google Maps API v2 和 jQuery 的示例,但不只是简单的旧 Google Maps API v3.
<html lang="zh-cn"><头><title>带有谷歌地图的 jQuery 移动版 - 谷歌地图 jQuery 插件</title><link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css"/><script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script><script type="text/javascript" src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script><script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3&sensor=false&language=en"><script type="text/javascript">var cityList = [['芝加哥',41.850033,-87.6500523,1],['伊利诺伊州', 40.797177,-89.406738, 2]];var demoCenter = new google.maps.LatLng(41,-87);无功地图;函数初始化(){map = new google.maps.Map(document.getElementById('map_canvas'), {变焦:7,中心:演示中心,mapTypeId: google.maps.MapTypeId.ROADMAP});添加标记();}函数 addMarkers(){var 标记,我;var infowindow = new google.maps.InfoWindow();for (i = 0; i < cityList.length; i++){标记 = 新的 google.maps.Marker({位置:新 google.maps.LatLng(cityList[i][1], cityList[i][2]),地图:地图,标题:cityList[i][0]});google.maps.event.addListener(marker, 'click', (function(marker, i) {var contentString = ''+''+''+ "这个位置是:<br>"+ 标记.title+'
'+''+ '</div>';返回函数(){infowindow.setContent(contentString);infowindow.open(地图,标记);google.maps.event.addListener(infowindow, 'click', (function(i){alert("您点击了信息窗口" + cityList[i][0]);}));}})(标记, i));}}头部><body onload="初始化()"><div id="basic-map" data-role="page"><div data-role="header"><h1><a data-ajax="false" href="/">jQuery mobile with Google maps v3</a>示例<a data-rel="back">Back</a>
<div data-role="内容"><div class="ui-bar-c ui-corner-all ui-shadow" style="padding:1em;"><div id="map_canvas" style="height:350px;"></div>