cObject
---cWebObject
------cWebGeoLocation
The cWebGeoLocation class provides an API for querying the user's current GEO location. It is a direct wrapper of the HTML5 geolocation API. The location is provided in GPS coordinates together information about the accuracy, traveling speed and direction. Note that the web application needs to gain permission before being allowed access to this information. Most browsers require the page to be loaded in a secure context (SSL/HTTPS) and will ask the end user for permission to access the location.
Querying the location is an asynchronous process and can be done once (using QueryLocation) and continuously using the tracking mode. To query the location once, a single call to QueryLocation can be done and a callback function should be provided that will receive the data.
The example below shows this process where GeoQuery_Callback is passed into QueryLocation as callback function.
Object oWebGeoLocation1 is a cWebGeoLocation End_Object Object oQueryOnceBtn is a cWebButton Set psCaption to "Show location" Procedure GeoQuery_Callback Integer iErr Number nLatitude Number nLongitude ; Number nAccuracy Number nSpeed Number nHeading If (not(iErr)) Begin Send ShowInfoBox ; (SFormat("Lat: %1 Long: %2 Acc: %3 Speed: %4 Head: %5", nLatitude, nLongitude, nAccuracy, nSpeed, nHeading)) End End_Procedure WebPublishProcedure GeoQuery_Callback Procedure OnClick Send QueryLocation of oWebGeoLocation1 (RefProc(GeoQuery_Callback)) Self End_Procedure End_Object
The Start and Stop procedures can be used to start and stop the continuous location tracking. The pbTracking web property indicates if tracking is currently enabled or not. If pbAutoStart is True, the tracking will start automatically when the view in which the object is placed is shown or when the application is loaded if placed outside of the view.
The example below shows how tracking is used to show the location inside a label.
Object oWebGeoLbl is a cWebLabel Set piColumnSpan to 0 Set psCaption to "GeoLocation: ..." End_Object Object oWebGeoLocation is a cWebGeoLocation Set pbAutoStart to True Procedure OnLocationChange Number nLatd Number nLongtd Number nAccuracy Number nSpeed Number nHeading Forward Send OnLocationChange nLatitude nLongitude nAccuracy nSpeed nHeading WebSet psCaption of oWebGeoLbl to ; (SFormat("GeoLocation: Lat: %1 Long: %2 Acc: %3 Speed: %4 Head: %5", nLatd, nLongtd, nAccuracy, nSpeed, nHeading)) End_Procedure End_Object