Ejemplo n.º 1
0
        private static void SetLocation()
        {
            if (!Conf.GetLocation)
            {
                return;
            }
            var localObj = new GetLocationObject();

            localObj.type    = Conf.LocationType != "" ? Conf.LocationType : "wgs84";
            localObj.success = (res) => {
                Adapter.SetStorageSync(BeaconSdk.Prefix + BeaconSdk.Lt, res.ToString());
            };
            // Adapter.getLocation(localObj);
        }
Ejemplo n.º 2
0
        public static void GetLocation(GetLocationObject obj)
        {
            try {
                Debugger.Log("GetLocation: {0}", Input.location);

                obj.fail?.Invoke("ERROR");
                // First, check if user has location service enabled
                if (!Input.location.isEnabledByUser)
                {
                    // Start service before querying location
                    Input.location.Start();
                }

                // Wait until service initializes
                int maxWait = 20;
                while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
                {
                    maxWait--;
                }

                // Service didn't initialize in 20 seconds
                if (maxWait < 1)
                {
                    Debugger.Log("Timed out");
                }

                // Connection has failed
                if (Input.location.status == LocationServiceStatus.Failed)
                {
                    Debugger.Log("Unable to determine device location");
                }
                else
                {
                    // Access granted and location value could be retrieved
                    Debugger.Log("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
                }
                // Stop service if there is no need to query location updates continuously
                Input.location.Stop();
            } catch (System.Exception e) {
                Debugger.Log(e.ToString());
                throw;
            }
        }