Ejemplo n.º 1
0
        private double[] GetCurrentLocation()
        {
            double[] data     = new double[2];
            int      platform = 0;

            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                platform = 1;
                break;
            }

            if (platform == 0) // Android
            {
                IGeolocator locator = DependencyService.Get <IGeolocator>();
                double      currentLatitude = 0, currentLongitude = 0;
                locator.locationObtained += (sender, e) =>
                {
                    currentLatitude  = e.lat;
                    currentLatitude  = Math.Round(currentLatitude * 100000.00) / 100000.00;
                    currentLongitude = e.lng;
                    currentLongitude = Math.Round(currentLongitude * 100000.00) / 100000.00;
                };
                locator.ObtainMyLocation();
                data[0] = currentLatitude;
                data[1] = currentLongitude;
            }
            else // iOS
            {
                data[0] = MainPage.currrentLatitude;
                data[1] = MainPage.currentLongitude;
            }

            return(data);
        }
Ejemplo n.º 2
0
        private void SetLocation()
        {
            IGeolocator locator = DependencyService.Get <IGeolocator>();

            locator.locationObtained += (sender, e) =>
            {
                UserLatitude  = e.lat;
                UserLatitude  = Math.Round(UserLatitude * 100000.00) / 100000.00;
                userLatitude  = UserLatitude;
                UserLongitude = e.lng;
                UserLongitude = Math.Round(userLongitude * 100000.00) / 100000.00;
                userLongitude = UserLongitude;
            };
            locator.ObtainMyLocation();

            Debug.WriteLine("userLatitude: " + userLatitude + ", userLongitude: " + userLongitude);

            userOffset = new DateTimeOffset(DateTime.Now).Offset.Hours;

            DateLocation defaultSettings = new DateLocation
            {
                myDate      = DateTime.Now,
                myLatitude  = userLatitude,
                myLongitude = userLongitude,
                myOffset    = userOffset
            };

            Application.Current.Properties["Default"] = defaultSettings;
        }