我有一个为学校项目编写的 jsp 页面,我使用 jquery mobile 和 js 代码来显示业务位置....
我页面中的问题是,当控制器 servlet 指向时,用于显示地图的画布未显示那个页面。刷新后画布显示完全正常。有人可以帮我理解我做错了什么吗?
编码:
<!DOCTYPE HTML>
<%@page import="org.softwarelabs.mosheudi.hit.j2ee.db.Coupon"%>
<HTML>
<head>
<meta charset="UTF-8">
<title>coupon site</title>
<% Coupon presentedCoupon = (Coupon)request.getAttribute("Requested coupon");
boolean addCalling = true;%>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
if (screen.width > 699) {
<%addCalling = false; %>
}</script>
<script>
var geocoder;
var map;
function initialize(myAddress) {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
geocoder.geocode( { 'address': myAddress}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
function codeAddress(myAddress)
{
geocoder.geocode( { 'address': myAddress}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
</script>
</head>
<body>
<div data-role="page" id="couponDetails" data-add-back-btn="true" style="background-color: #00B2EE">
<div data-role="header">
<h1> Coupon information </h1>
</div>
<div data-role="content" data-inset="true" style="background-color: #00B2EE">
<div class="ui-grid-b" id="couponInfo">
<div class="ui-block-a" id="CtextDetails">
<h1> Coupon details </h1><br>
<ul>
<h3> <%= presentedCoupon.getM_CouponName() %> </h3><br>
<p><strong> Price: <%= presentedCoupon.getM_CouponPrice() %> </strong></p>
<p><strong> Expiration date: <%= presentedCoupon.getM_ExpireDate() %> </strong></p>
</ul>
</div>
<div class="ui-block-b" id="couponImg">
<p><img src="<%=(presentedCoupon.getM_imgUrl() != null)?presentedCoupon.getM_imgUrl():"Images/pictures/question_mark.png" %>" alt="coupon photo" style="width: 80%"/></p>
</div>
<div class="ui-block-c" >
<a href="#" data-theme="e" ><img align="right" align="bottom" alt="buy" src="Images/pictures/buy-now.png" style="width: 40%"></a>
</div>
</div> <!-- couponInfo-->
<img src="Images/pictures/line.png" alt="coupon photo" style="width: 100%"/>
<div class="ui-grid-a" id="businessInfo">
<div class="ui-block-a" id="BtextDetails">
<h1> Business information </h1>
<ul>
<p><strong> <%=presentedCoupon.getM_Business().getBusinessName() %> </strong></p>
<p> <%=presentedCoupon.getM_Business().getM_BusinessAddress() %> </p>
<p> Phone number : <%=presentedCoupon.getM_Business().getM_BusinessPhone() %></p>
<%if(addCalling){ %>
<a href="<%=presentedCoupon.getM_Business().getM_BusinessPhone() %>" data-mini="true" data-role="button" data-icon="info"> Call </a>
<%} %>
<div id="map_canvas" style="width: 300px; height: 300px;" onload="initialize('<%=presentedCoupon.getM_Business().getM_BusinessAddress()%>')"></div>
</ul>
</div>
<div class="ui-block-b" id="businessImg">
<p><img src="<%=presentedCoupon.getM_Business().getM_imgUrl() %>" alt="business Image" style="width: 80%"/></p>
<% if(addCalling){ %>
<a href="useGPSHere" data-role="button" rel="external" data-icon="search"> Navigate </a>
<%}else{ %>
<a href="https://maps.google.co.il/maps" data-role="button" rel="external" data-icon="search"> Navigate </a>
<%} %>
</div>
</div>
</div><!-- content-->
</div>
<script>
initialize('<%=presentedCoupon.getM_Business().getM_BusinessAddress()%>');
</script>
</body>
</HTML>