我的迭代器有4个值,即mumbai,thane,nagpur,pune。
我想在Google地图上显示这些值。
我有这些值的迭代器。但在JavaScript中,我只能得到第一个值,即孟买。
我的问题是:点击特定按钮后,如何在Google地图上显示这些值?
function initialize()
{
var address = document.getElementById("ven").value;
//alert(address);
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': address}, function(results, status) {
var location = results[0].geometry.location;
var lat = location.lat();
var long = location.lng();
// alert('LAT: ' + lat + ' LANG: ' + long);
var myCenter = new google.maps.LatLng(lat, long);
var mapProp = {
center: myCenter,
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
var marker = new google.maps.Marker({
position: myCenter,
animation: google.maps.Animation.BOUNCE
});
marker.setMap(map);
});
}
google.maps.event.addDomListener(document.getElementById('show'), 'click', initialize);
<%@ include file="jshome.jsp" %>
<section class="container">
<div class="login">
<s:if test="%{jfList.isEmpty()}">
<h1>Sorry!!Currently no job fairs are there..</h1>
</s:if>
<s:else>
<h1>All Job Fairs</h1>
<s:iterator value="jfList">
<table cellspacing="10">
<tr >
<td><b>Title</b></td>
<td><s:property value="title"/></td>
</tr>
<tr>
<td><b>Message</b></td>
<td><s:property value="message"/></td>
</tr>
<tr>
<td><b>Event Date</b></td>
<td><s:property value="date"/></td>
<!-- <td><s:label name="date" label="Event Date "/></td>-->
</tr>
<tr>
<td><b>Venue</b></td>
<td><s:property value="venue" /></td>
<s:hidden id="ven" name="venue" label="Venue "/>
</tr>
<tr>
<td><b>Recruiters</b></td>
<td><s:property value="recruiters"/></td>
<!-- <td><s:label name="recruiters" label="Recruiters "/></td>-->
</tr>
<tr>
<td><input id="show" type="button" value="Show Map" onclick="initialize();"></td>
</tr>
<br>
<br>
</table>
</s:iterator>
</s:else>
答案 0 :(得分:0)
event.addDomListener(document.getElementById('show'), 'click', initialize);
document.getElementById("ven")
为该字段指定唯一ID:
<s:hidden id="UniqueID" name="venue" label="Venue "/>
并在按钮中使用相同的内容:
<input class="show" type="button" value="Show Map" onclick="initialize('UniqueID');">
然后你可以做
funtion initialize(id) {
var address = document.getElementById(id).value;