UNPKG

@genexus/web-standard-functions

Version:

GeneXus JavaScript standard functions library for web generators

217 lines 7.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GeneXusCommonGeolocationInfoData = exports.GeneXusCommonGeolocation = void 0; const helpers_1 = require("../../misc/helpers"); class GeneXusCommonGeolocation { /** * Returns the current location for the device * @param minAccuracy * @param timeout * @param includeHeadingAndSpeed * @param ignoreErrors * @return any */ static getMyLocation(minAccuracy, timeout, includeHeadingAndSpeed, ignoreErrors) { return new Promise((resolve, reject) => { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition((position) => { let geoPosition = new GeneXusCommonGeolocationInfoData(); geoPosition.Location = position.coords.latitude.toString() + "," + position.coords.longitude.toString(); geoPosition.Heading = position.coords.heading; geoPosition.Precision = position.coords.accuracy; geoPosition.Description = ""; geoPosition.Speed = position.coords.speed; geoPosition.Time = position.timestamp; resolve(geoPosition); }, (error) => { if (ignoreErrors) { let geoPosition = new GeneXusCommonGeolocationInfoData(); geoPosition.Time = null; resolve(geoPosition); } else { reject("Could not get location information (" + error.message + ")"); } }, { timeout: timeout * 1000 }); } else { if (ignoreErrors) { let geoPosition = new GeneXusCommonGeolocationInfoData(); geoPosition.Time = null; resolve(geoPosition); } else { reject("Could not get location information (geolocation service not available)"); } } }); } /** * Indicates wether the application has been given permission to use location services * @return boolean */ static authorized() { return this.serviceEnabled(); } /** * Indicates wether location services are enable in the device * @return boolean */ static serviceEnabled() { return navigator.geolocation ? true : false; } /** * Starts generating tracking information * @param changesInterval * @param distance * @param action * @param actionTimeInterval * @param accuracy * @return any */ static startTracking(changesInterval, distance, action, actionTimeInterval, accuracy) { (0, helpers_1.notImplemented)('GeneXusCommonGeolocation.startTracking'); return null; } /** * Stops the generation of tracking information * @return any */ static endTracking() { (0, helpers_1.notImplemented)('GeneXusCommonGeolocation.endTracking'); return null; } /** * Returns a collection of location information generated by the tracking methods * @param startTime * @return any */ static getLocationHistory(startTime) { (0, helpers_1.notImplemented)('GeneXusCommonGeolocation.getLocationHistory'); return null; } /** * Removes all previous location information generated by the tracking methods * @return any */ static clearLocationHistory() { (0, helpers_1.notImplemented)('GeneXusCommonGeolocation.clearLocationHistory'); return null; } /** * Returns the latitude of the given location * @param location * @return number */ static getLatitude(location) { if (location.Location.indexOf(",") > -1) { return parseFloat(location.Location.split(",")[0]); } return 0; } /** * Returns the longitude of the given location * @param location * @return number */ static getLongitude(location) { if (location.Location.indexOf(",") > -1) { return parseFloat(location.Location.split(",")[1]); } return 0; } /** * Returns the distance between the two locations given (haversine formula) * @param fromLocation * @param toLocation * @return number */ static getDistance(fromLocation, toLocation) { const R = 6371e3; // earth’s radius const lat1 = this.getLatitude(fromLocation); const lon1 = this.getLongitude(fromLocation); const lat2 = this.getLatitude(toLocation); const lon2 = this.getLongitude(toLocation); const lat1radians = this.toRadians(lat1); const lat2radians = this.toRadians(lat2); const latRadians = this.toRadians(lat2 - lat1); const lonRadians = this.toRadians(lon2 - lon1); const a = Math.sin(latRadians / 2) * Math.sin(latRadians / 2) + Math.cos(lat1radians) * Math.cos(lat2radians) * Math.sin(lonRadians / 2) * Math.sin(lonRadians / 2); const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return Math.round(R * c); } /** * Returns a collection of addresses for the given location * @param location * @return any */ static getAddress(location) { (0, helpers_1.notImplemented)('GeneXusCommonGeolocation.getAddress'); return null; } /** * Returns a collection of locations for the given address * @param address * @return any */ static getGeolocation(address) { (0, helpers_1.notImplemented)('GeneXusCommonGeolocation.getGeolocation'); return null; } /** * @param proximityAlerts * @return boolean */ static setProximityAlerts(proximityAlerts) { (0, helpers_1.notImplemented)('GeneXusCommonGeolocation.setProximityAlerts'); return false; } /** * @return any */ static getProximityAlerts() { (0, helpers_1.notImplemented)('GeneXusCommonGeolocation.getProximityAlerts'); return null; } /** * @return any */ static getCurrentProximityAlert() { (0, helpers_1.notImplemented)('GeneXusCommonGeolocation.getCurrentProximityAlert'); return null; } /** * @return any */ static clearProximityAlerts() { (0, helpers_1.notImplemented)('GeneXusCommonGeolocation.clearProximityAlerts'); return null; } /** * @param geoLocationPickerParameters * @return any */ static pickLocation(geoLocationPickerParameters) { (0, helpers_1.notImplemented)('GeneXusCommonGeolocation.pickLocation'); return null; } static toRadians(val) { const PI = 3.1415926535; return val / 180.0 * PI; } } exports.GeneXusCommonGeolocation = GeneXusCommonGeolocation; class GeneXusCommonGeolocationInfoData { constructor() { this.Location = ""; this.Description = ""; this.Time = new Date(); this.Precision = 0; this.Heading = 0; this.Speed = 0; } } exports.GeneXusCommonGeolocationInfoData = GeneXusCommonGeolocationInfoData; //# sourceMappingURL=geolocation.js.map