来源:http://www.imcoder.org/mobile/210546.htm
I'm building a mobile web site with mvc on iis5. This site will be accessible by blackberry devices equipped with a built in gps.
Here is one of my page
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
<% if( ( TempData["ErrorMsg"] ?? ViewData.ErrorMsg ) != null ){ %>
<p class="error">
<% =TempData["ErrorMsg"] ?? ViewData.ErrorMsg %></p>
<% } %>
<%using (Html.Form<MyController>(p => p.GetNextView(Guid.NewGuid()), FormMethod.Post, new { _id = "formindex" }))
{ %>
<%=string.Format(GTSResources.GetLocalizedText("CurrentStateMsg"), ViewData.CurrentState)%>
<br />
<br />
<%=GTSResources.GetLocalizedText("CurrentStateChoiceMsg")%>
<%=Html.Select("DesiredState", ViewData.PossibleStateTransition)%>
<%=Html.Hidden("GpsCoordinate", null)%>
<%=Html.Hidden("PreviousPage", "Index")%>
<br />
<br />
<%=Html.SubmitButton("submit", GTSResources.GetLocalizedText("SubmitBtnText"), new { _onclick = "SetGps();"})%>
<%} %>
<script type="text/javascript">
function SetGps()
{
if(blackberry.location.GPSSupported)
{
blackberry.location.setAidMode(1);
blackberry.location.refreshLocation();
document.formindex.elements['GpsCoordinate'].value = blackberry.location.latitude + "," + blackberry.location.longitude;
}
window.alert(document.formindex.elements['GpsCoordinate'].value);
return true;
};
</script>
</asp:Content>
The problem i'm facing is that the GpsCoordinate element is only updated correctly the first time the page is called. Whenever i'm calling this page again the value remains the same.
But if i put a breakpoint on the server side and wait for 5 seconds before continuing then the GpsCoordinate gets updated correctly everytime.
I was thinking that maybe the page is being cache on the server and breaking into the code makes it refresh the page? I've tried setting iis to expire content immediately but it doesn't change anything?
I even tried setting unique url with a Guid at the end just to make sure nothing woud be cache.
Is the problem in my javascript called or on the server side or ???
Any help would be very appreciate.
thanks
Hello!
This behavior seems to be typical for the BlackBerry JavaScript Location API. I had the same issue in my GPS application. For my experience the Location API works only with the BlackBerry Browser Version 4.3 (8130 emulator). It is also helpfull to request gps coordinates with different aid modes.