以下はモバイル用コードです。ブラウザ用には特に機能はありません、モジュールをインポートして確認してください。
<%@ Control Language="c#" AutoEventWireup="true" Inherits="CSPortal.PortalModule.MobilePortalModuleControl" TargetSchema="http://schemas.microsoft.com/Mobile/WebUserControl" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<%@ Register TagPrefix="mportal" TagName="Title" Src="~/Parts/P_MModuleTitle.ascx" %>
<%@ Register TagPrefix="mportal" Namespace="CSPortal.MobileControls" Assembly="CSPortal" %>
<%@ import Namespace="CSPortal" %>
<script language="c#" runat="server">
string sessionheader = "Form2XSLT:";
void Page_Load(object sender, EventArgs e)
{
//Insert code here
if(!this.IsPostBack)
{
if(!IsEditable || Request.QueryString["itemid"] != null)
{ //編集権限のない場合は非表示
HoleDiv.Visible = false;
return;
}
//レンダリング計算値を計算して追加する。
this.RenderedWeight = this.ModuleWeight; //ModuleWeightにはモジュール別アンカーのレンダリング量は加算済み。
//イメージ計算値を計算して追加する。
this.RenderedImageWeight = this.ImageWeight;
string alias = "((CSPortal.MobileDesktopDefault)Page).portalSettings.ActiveMenu.URLAlias;
if(alias == "")
{
HiddenLabel.Text = "URLエイリアスが設定されていませんので正常に動作しません";
HiddenLabel.Visible = true;
}
gps2imode.NavigateUrl = "../" + alias + "dd.aspx?" + FormsAuthentication.FormsCookieName + "=" + Request[FormsAuthentication.FormsCookieName];
base2au.NavigateUrl = "device:location?url=http://" + Request.Url.Host + Request.ApplicationPath + "/" + alias + "dd.aspx";
gps2au.NavigateUrl = "device:gpsone?url=http://" + Request.Url.Host + Request.ApplicationPath + "/" + alias + "dd.aspx&ver=1&datum=0&unit=0&acry=0&number=0"; //後ろは?ではなく&にする
base2sb.NavigateUrl = "../" + alias + "dd.aspx?" + FormsAuthentication.FormsCookieName + "=" + Request[FormsAuthentication.FormsCookieName];
gps2sb.NavigateUrl = "location:auto?url=http://" + Request.Url.Host + Request.ApplicationPath + "/" + alias + "dd.aspx";
//i-mode,auの経度緯度
if(Request.QueryString["lat"] != null)
Latitude.Text = Request.QueryString["lat"];
if(Request.QueryString["lon"] != null)
Longitude.Text = Request.QueryString["lon"];
//sbの経度緯度、日本近辺のみ
if(Request.QueryString["pos"] != null)
{
string [] posa = "Request.QueryString[""pos"].Split('E');
string [] posn = "posa[0].Split('.');
Latitude.Text = posn[0].Substring(1) + "." + posn[1] + "." + posn[2] + "." + posn[3];
string [] pose = "posa[1].Split('.');
Longitude.Text = pose[0] + "." + pose[1] + "." + pose[2] + "." + pose[3];
}
else if(Request.Headers["x-jphone-geocode"] != null)
{ //簡易
string [] posa = Request.Headers["x-jphone-geocode"].Split('%');
Latitude.Text = posa[0].Substring(0, 2) + "." + posa[0].Substring(2, 2) + "." + posa[0].Substring(4, 2);
Longitude.Text = posa[1].Substring(2, 3) + "." + posa[1].Substring(5, 2) + "." + posa[1].Substring(7, 2);
}
//精度
int accurate = 0; //簡易測地
if(Request.QueryString["x-acc"] != null)
accurate = int.Parse(Request.QueryString["x-acc"]); //i-mode
else if(Request.QueryString["x-acr"] != null)
accurate = int.Parse(Request.QueryString["x-acr"]); //sb
else if(Request.QueryString["fm"] != null)
{ //au
int fm = int.Parse(Request.QueryString["fm"]);
if(fm == 0)
accurate = 3;
else if(fm <= 2)
accurate = 2;
else if(fm <= 5)
accurate = 1;
}
Accurate.Text = "簡易";
Scale.Text = "4"; //広域
for(int vi = 0; vi < accurate; vi++)
{
if(vi == 0)
Accurate.Text = "";
Accurate.Text += "★";
Scale.Text = "3"; //狭域
}
#if false
//参照sb
if(Request.Headers["x-jphone-geocode"] != null)
result.Text = Request.Headers["x-jphone-geocode"];
else
result.Text = Request.Url.Query;
#endif
//定型フォーム入力へ引き渡せるようにする
if(Latitude.Text != "" && Longitude.Text != "" && Scale.Text != "")
{
Message2.Visible = MapBtn.Visible = CancelBtn.Visible = ParaHolder.Visible = true;
Message.Visible = false;
SetParam(Latitude.Text, Longitude.Text, Scale.Text);
}
//GSP機能呼び出し切り替え
if(CSPortal.Common.IsEZweb() && !CSPortal.Common.IsEZwebHDML())
{ //au
base2au.Visible = gps2au.Visible = true;
this.RenderedWeight += Common.GetRenderedURL(base2au.NavigateUrl); //相対URLのレンダリングサイズ計算
this.RenderedWeight += Common.GetRenderedURL(gps2au.NavigateUrl);
}
else if(CSPortal.Common.IsVodafone())
{ //sb
base2sb.Visible = gps2sb.Visible = true;
this.RenderedWeight += Common.GetRenderedURL(base2sb.NavigateUrl);
this.RenderedWeight += Common.GetRenderedURL(gps2sb.NavigateUrl);
}
else
{ //i-mode
gps2imode.Visible = true;
this.RenderedWeight += Common.GetRenderedURL(gps2imode.NavigateUrl);
}
}
}
void CancelBtn_Click(object sender, EventArgs e)
{
//定型フォーム入力への引渡しをキャンセルする
Session[sessionheader + "TEXT:Latitude"] = null;
Session[sessionheader + "TEXT:Longitude"] = null;
Session[sessionheader + "TEXT:Scale"] = null;
Message2.Visible = MapBtn.Visible = CancelBtn.Visible = ParaHolder.Visible = false;
Message.Visible = true;
}
void MapBtn_Click(object sender, EventArgs e)
{
//TextBoxから取り込み設定する
string latstr = "";
string lonstr = "";
string scalestr = "";
if(Latitude.Text != "")
latstr = Latitude.Text;
if(Longitude.Text != "")
lonstr = Longitude.Text;
if(Scale.Text != "")
scalestr = Scale.Text;
if(latstr == "" || lonstr ="=" "" || scalestr ="=" "")
return;
//測地系変換、セッション変数保存
SetParam(latstr, lonstr, scalestr);
//Yahoo!地図情報へリダイレクト、参)map.yahoo.co.jpだとブラウザへ
string url = "http://map.mobile.yahoo.co.jp/pl?mode=map&lat=" + (string)Session[sessionheader + "TEXT:Latitude"]
+ "&lon=" + (string)Session[sessionheader + "TEXT:Longitude"] + "&sc=" + scalestr;
MobilePage MPage = "new" MobilePage();
MPage.RedirectToMobilePage(url);
}
//測地系変換、セッション変数保存
void SetParam(string latstr, string lonstr, string scalestr)
{
string [] lata = "latstr.Split('.');
string [] lona = "lonstr.Split('.');
if(lata.Length == 4)
lata[2] += "." + lata[3];
if(lona.Length == 4)
lona[2] += "." + lona[3];
double dlat = "double.Parse(lata[0])" + double.Parse(lata[1]) / 60 + double.Parse(lata[2])/3600;
double dlon = double.Parse(lona[0]) + double.Parse(lona[1]) / 60 + double.Parse(lona[2])/3600;
//wgs84->tokyo
if(Request.QueryString["geo"] == null || Request.QueryString["geo"] != "tokyo")
{ //sbの日本測地系のみ処理しない
dlat = 1.000106961*dlat - 0.000017467*dlon - 0.004602017;
dlon = 0.000046047*dlat + 1.000083049*dlon - 0.010041046;
}
latstr = dlat.ToString(".000000");
lonstr = dlon.ToString(".000000");
//定型入力フォームの地図情報へデータを引き渡す。受け取り手の定型入力フォームと名前を整合させる必要がある。
Session[sessionheader + "TEXT:Latitude"] = latstr;
Session[sessionheader + "TEXT:Longitude"] = lonstr;
Session[sessionheader + "TEXT:Scale"] = scalestr;
}
</script>
<!--Program start-->
<mportal:title runat="server" id="ModuleTitle" moduleweight="400" imageweight="0"></mportal:title>
<mobile:label id="HiddenLabel" runat="server" breakafter="true" stylereference="error" visible="false"></mobile:label>
<div id="HoleDiv" runat="server">
<!--Insert HTML here-->
<asp:label id="Message" runat="server>GPS機能付き携帯端末から現在地を取得できます。:<br" /></asp:label>
<asp:label id="Message2" runat=server visible=false>現在地を取得しました。対応する定型入力フォームの編集時に取得パラメータがセットされます。:<br /></asp:label>
<mobile:command id="MapBtn" runat="server" text="再取込&Map確認" onclick="MapBtn_Click" visible="false></mobile:command>
<mobile:command id="CancelBtn" runat="server" text="キャンセル" onclick="CancelBtn_Click" visible=false causesvalidation="false"></mobile:command>
<div>
<asp:hyperlink id="gps2imode" runat="server" lcs visible="false>iモードGPS<br" /></asp:hyperlink>
<asp:hyperlink id="base2au" runat="server" visible=false>au簡易位置<br /></asp:hyperlink>
<asp:hyperlink id="gps2au" runat="server" visible="false>auGPS<br" /></asp:hyperlink>
<asp:hyperlink id="base2sb" runat="server" z visible=false>S.B.簡易位置<br /></asp:hyperlink>
<asp:hyperlink id="gps2sb" runat="server" visible="false>S.B.GPS<br" /></asp:hyperlink>
</div>
<!-- a href="device:gpsone?url=http://map.mobile.yahoo.co.jp/navi/k=&ver=1&datum=0&unit=0&acry=0&number=0">参)現在地からYahooMap検索</a><br / -->
<!-- 参)URI=<asp:textbox id=result runat=server></asp:textbox><br / -->
<asp:placeholder id="ParaHolder" runat="server" visible="false>
<div>
精度:<asp:label id="Accurate" runat="server></asp:label><br" />
緯度+1秒で30m北<br />
経度+1秒で25m東<br />
<!-- 緯度+0.0001で10m北<br />
経度+0.0001で9m東<br / -->
<mobile:RegularExpressionValidator runat="Server" ControlToValidate="Latitude" ValidationExpression="^[\d.+-]{1,20}$" ErrorMessage="半角数字と.で20文字まで" Display="Dynamic" breakafter="true" />
Lat=<asp:textbox id="Latitude" istyle="4" runat="server></asp:textbox><br" />
<mobile:RegularExpressionValidator runat="Server" ControlToValidate="Longitude" ValidationExpression="^[\d.+-]{1,20}$" ErrorMessage="半角数字と.で20文字まで" Display="Dynamic" breakafter="true"/>
Lon=<asp:textbox id="Longitude" istyle="4" runat="server></asp:textbox><br" />
<mobile:rangevalidator runat="server" minimumvalue="1" maximumvalue="9" type="Integer" display="Dynamic" errormessage="1~9を入力" controltovalidate="Scale" breakafter="true"/>
Scale=<asp:textbox id="Scale" istyle="4" runat="server>3</asp:textbox><br" />
</div>
</asp:placeholder>
<hr />
</div>
<!--Program end-->