Geolocation

TsgcHTMLComponent_Geolocation reads the position of the device with the browser Geolocation API and delivers it to the server, once per request or continuously, from a visible panel or from a hidden one, in Delphi, C++ Builder, Lazarus and .NET.

TsgcHTMLComponent_Geolocation

Choose ShowUI and UpdateMode, set WSSend or Action, then read the HTML property. Every reading arrives on the server as geo_lat, geo_lng, geo_accuracy and the other geo_* fields.

Component class

TsgcHTMLComponent_Geolocation

Renders

Locate panel or hidden panel + nine hidden fields + inline script

Languages

Delphi, C++ Builder, Lazarus, .NET

Track a position in the background

No library to bundle and nothing pulled from a CDN: the position comes from the browser Geolocation API. Serve the page over HTTPS, or from localhost while developing, because browsers only expose geolocation in a secure context.

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

Key properties & methods

The members you reach for most often.

ShowUI

True (default) renders a Locate button, a Stop button in continuous mode, a status line with latitude, longitude and accuracy, and the optional OpenStreetMap link of ShowMapLink. False renders nothing visible, so the panel starts from AutoStart or from el.sgcGeoStart() and el.sgcGeoStop().

UpdateMode

gumOnce (default) delivers one reading per start. gumContinuous keeps watching until stopped, throttled by MinIntervalMs (default 5000) and MinDistanceMeters (default 0).

Position options

EnableHighAccuracy (default True), TimeoutMs (default 10000) and MaximumAgeMs (default 0) are passed to the browser with every request.

FieldName

Prefix of the nine hidden fields, default geo: latitude, longitude, accuracy, altitude, altitude accuracy, heading, speed, timestamp and geo_error.

WSSend / Action / RedirectURL

Push every reading over the sgc WebSocket, POST it to Action, or navigate to RedirectURL with the position in the query string. TargetSelector writes lat,lng into another element of the page.

Errors

geo_error reports permission_denied, position_unavailable, timeout, insecure_context or not_supported. A sgcGeolocation:position DOM event fires on every reading.

Keep exploring

Online HelpFull API reference and usage guide for this component.
All sgcHTML ComponentsBrowse the full feature matrix of 80+ components.
Download Free TrialThe 30-day trial ships the 60.HTML demo projects.
PricingSingle, Team and Site licenses with full source code.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Get Started?

Download the free trial and start building web UIs in Delphi, C++ Builder and .NET.