Geolocation
TsgcHTMLComponent_Geolocation 使用浏览器 Geolocation API 读取设备位置并将其送达服务器,可按请求单次读取或持续读取,既可使用可见面板也可使用隐藏面板,适用于 Delphi、C++ Builder、Lazarus 和 .NET。
TsgcHTMLComponent_Geolocation 使用浏览器 Geolocation API 读取设备位置并将其送达服务器,可按请求单次读取或持续读取,既可使用可见面板也可使用隐藏面板,适用于 Delphi、C++ Builder、Lazarus 和 .NET。
选择 ShowUI 和 UpdateMode,设置 WSSend 或 Action,然后读取 HTML 属性。每次读数都会以 geo_lat、geo_lng、geo_accuracy 及其他 geo_* 字段的形式到达服务器。
TsgcHTMLComponent_Geolocation
定位面板或隐藏面板 + 九个隐藏字段 + 内联脚本
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(默认)每次启动只提交一次读数。gumContinuous 会持续监视直到停止,并受 MinIntervalMs(默认 5000)和 MinDistanceMeters(默认 0)限制频率。
EnableHighAccuracy(默认 True)、TimeoutMs(默认 10000)和 MaximumAgeMs(默认 0)会随每次请求传递给浏览器。
九个隐藏字段的前缀,默认为 geo:纬度、经度、精度、海拔、海拔精度、航向、速度、时间戳和 geo_error。
通过 sgc WebSocket 推送每一次读数,将其 POST 到 Action,或跳转到 RedirectURL 并在查询字符串中附带位置。TargetSelector 会把 lat,lng 写入页面中的另一个元素。
geo_error 会报告 permission_denied、position_unavailable、timeout、insecure_context 或 not_supported。每次读数都会触发一个 sgcGeolocation:position DOM 事件。