Geolocation
TsgcHTMLComponent_Geolocation は、Delphi、C++ Builder、Lazarus、.NET で、ブラウザーの Geolocation API を使ってデバイスの位置を取得し、リクエストごとに1回、または継続的に、表示されるパネルまたは非表示のパネルからサーバーへ送ります。
TsgcHTMLComponent_Geolocation は、Delphi、C++ Builder、Lazarus、.NET で、ブラウザーの Geolocation API を使ってデバイスの位置を取得し、リクエストごとに1回、または継続的に、表示されるパネルまたは非表示のパネルからサーバーへ送ります。
ShowUI と UpdateMode を選び、WSSend または Action を設定してから HTML プロパティを読み取ります。取得した位置は、geo_lat、geo_lng、geo_accuracy などの geo_* フィールドとしてサーバーに届きます。
TsgcHTMLComponent_Geolocation
位置取得パネルまたは非表示パネル + 9個の隠しフィールド + インラインスクリプト
Delphi, C++ Builder, Lazarus, .NET
同梱するライブラリはなく、CDN から読み込むものもありません。位置はブラウザーの Geolocation API から取得されます。ブラウザーは位置情報をセキュアコンテキストでのみ公開するため、ページは HTTPS で、開発中は localhost から配信してください。
uses
sgcHTML_Component_Geolocation;
var
oGeo: TsgcHTMLComponent_Geolocation;
begin
oGeo := TsgcHTMLComponent_Geolocation.Create(nil);
try
oGeo.GeolocationID := 'deliveryGeo';
oGeo.ShowUI := False; // no visible panel
oGeo.UpdateMode := gumContinuous; // keep watching until stopped
oGeo.MinIntervalMs := 30000;
oGeo.MinDistanceMeters := 50;
oGeo.AutoStart := True;
oGeo.WSSend := True; // push every reading over WebSocket
WebModule.Response := oGeo.HTML; // hidden fields + inline script
finally
oGeo.Free;
end;
end;
// includes: sgcHTML_Component_Geolocation.hpp
TsgcHTMLComponent_Geolocation *oGeo = new TsgcHTMLComponent_Geolocation(NULL);
try
{
oGeo->GeolocationID = "deliveryGeo";
oGeo->ShowUI = false;
oGeo->UpdateMode = gumContinuous;
oGeo->MinIntervalMs = 30000;
oGeo->MinDistanceMeters = 50;
oGeo->AutoStart = true;
oGeo->WSSend = true;
String html = oGeo->HTML; // hidden fields + inline script
}
__finally
{
delete oGeo;
}
using esegece.sgcWebSockets;
var geo = new TsgcHTMLComponent_Geolocation();
geo.GeolocationID = "deliveryGeo";
geo.ShowUI = false;
geo.UpdateMode = TsgcHTMLGeolocationUpdateMode.gumContinuous;
geo.MinIntervalMs = 30000;
geo.MinDistanceMeters = 50;
geo.AutoStart = true;
geo.WSSend = true;
string html = geo.HTML; // hidden fields + inline script
最もよく使うメンバーです。
既定値の True では、位置取得ボタン、継続モードでの停止ボタン、緯度・経度・精度を表示するステータス行、および ShowMapLink による OpenStreetMap へのリンク(任意)が描画されます。False では表示される要素は何も描画されず、パネルは AutoStart、または el.sgcGeoStart() と el.sgcGeoStop() から開始します。
既定値の gumOnce は、開始ごとに1回だけ位置を送ります。gumContinuous は停止するまで監視を続け、MinIntervalMs(既定値 5000)と MinDistanceMeters(既定値 0)で送信を間引きます。
EnableHighAccuracy(既定値 True)、TimeoutMs(既定値 10000)、MaximumAgeMs(既定値 0)は、リクエストのたびにブラウザーへ渡されます。
9個の隠しフィールドの接頭辞で、既定値は geo です。緯度、経度、精度、高度、高度の精度、進行方向、速度、タイムスタンプ、および geo_error が対象です。
取得したすべての位置を sgc の WebSocket 経由でプッシュするか、Action に POST するか、位置をクエリ文字列に付けて RedirectURL へ移動します。TargetSelector は lat,lng をページ内の別の要素に書き込みます。
geo_error は permission_denied、position_unavailable、timeout、insecure_context、not_supported のいずれかを報告します。位置を取得するたびに sgcGeolocation:position の DOM イベントが発火します。