示例#1
0
        private async void Celsius_Click(object sender, RoutedEventArgs e)
        {
            var position = await LocationManager.GetPosition();

            RootObject MyWeather = await OpenWeatherProxy.GetWeather(position.Coordinate.Latitude, position.Coordinate.Longitude);

            string icon = String.Format("ms-appx:///Assets/Weather/{0}.png", MyWeather.weather[0].icon);

            ResultImage.Source = new BitmapImage(new Uri(icon, UriKind.Absolute));
            NameTb.Text        = MyWeather.name;
            TempTb.Text        = "Temp: " + MyWeather.main.temp;
            DescTb.Text        = MyWeather.weather[0].description;
            var din = MyWeather.dt;

            System.DateTime Date = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
            Date       = Date.AddSeconds(din);
            dayTb.Text = "Date: " + Date.ToString("dd-MM-yyyy");
        }
        /* Peut etre execute en synchrone car recupere uste la position*/
        public void GetLocationAsync(String p_Provider)
        {
            LocationManager l_LocationManager = GetLocationManager();


            Initialisation BDD = new Initialisation();

            BDD.DBConnection();

            var locationCriteria = new Criteria
            {
                Accuracy         = Accuracy.Fine,
                PowerRequirement = Power.Medium
            };
            var locationProvider = l_LocationManager.GetBestProvider(locationCriteria, true);

            l_LocationManager.RequestLocationUpdates(p_Provider, MIN_TIME_FOR_UPDATE, MIN_DISTANCE_FOR_UPDATE, locationListener);
            var GPSEnabled = l_LocationManager.IsProviderEnabled(p_Provider);

            if (GPSEnabled)
            {
                if (l_LocationManager != null)
                {
                    Localisation location = new Localisation();

                    Location p_location = getLastKnownLocation();
                    if (p_location != null)
                    {
                        BDD.BDDConnection.DeleteAll <Localisation>();
                        location.Latitude  = (float)p_location.Latitude;
                        location.Longitude = (float)p_location.Longitude;
                        BDD.BDDConnection.InsertOrIgnore(location);
                    }
                }
            }
            else
            {
                Toast.MakeText(this, "GPS is disabled. It is required for the first start and to update position.", ToastLength.Long).Show();
            }

            BDD.BDDConnection.Close();
            return;
        }
        private Location getLastKnownLocation()
        {
            LocationManager l_LocationManager = GetLocationManager();
            List <string>   providers         = new List <string>(l_LocationManager.GetProviders(true));
            Location        bestLocation      = null;

            foreach (String provider in providers)
            {
                Location l = l_LocationManager.GetLastKnownLocation(provider);
                if (l == null)
                {
                    continue;
                }
                if (bestLocation == null || l.Accuracy < bestLocation.Accuracy)
                {
                    bestLocation = l;
                }
            }
            return(bestLocation);
        }
示例#4
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            #region -Fetch weather data from API-
            var position = await LocationManager.GetPosition();

            RootObjectF Forecast = await WeatherForecast.Forecast(position.Coordinate.Latitude, position.Coordinate.Longitude, 5);

            #endregion
            #region -Creating and binding into weather list-
            List <DayWeather> WeatherList = new List <DayWeather>();
            foreach (var tempDayWeather in Forecast.list)
            {
                DayWeather Dw = new DayWeather();
                Dw.Icon        = String.Format("ms-appx:///Assets/Weather/{0}.png", tempDayWeather.weather[0].icon);
                Dw.Description = tempDayWeather.weather[0].description + " | ";
                Dw.Temp        = tempDayWeather.temp.min.ToString() + " / " + tempDayWeather.temp.max.ToString();
                System.DateTime tDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
                Dw.WeatherDate = tDate.AddSeconds(tempDayWeather.dt).ToString("dd-MMM") + " | ";
                WeatherList.Add(Dw);
            }
            WeatherListB.ItemsSource = WeatherList;
            #endregion
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.
            //data.GetWeatherDataForCity("voorheesville");
            // this.View.BackgroundColor = UIColor.Blue;
            var search = new UISearchController(searchResultsController: null)
            {
                DimsBackgroundDuringPresentation = false
            };

            var searchdelegate = new UISearchBarDelegate();


            // ensures the segue works in the context of the underling ViewController, thanks @artemkalinovsky
            DefinesPresentationContext = true;

            NavigationItem.SearchController = search;
            search.SearchResultsUpdater     = this;
            Manager = new LocationManager();
            search.SearchBar.Hidden = true;

            search.SearchBar.Delegate = searchdelegate;

            search.SearchBar.Placeholder = "Enter a City Name or a Zip Code";



            if (Manager.DoesHaveAccesstoLocation())
            {
                Manager.StartLocationUpdates();
                double lat = Convert.ToDouble(Manager.LocMgr.Location.Coordinate.Latitude);
                double lon = Convert.ToDouble(Manager.LocMgr.Location.Coordinate.Longitude);

                weather = data.GetWeatherDataByCordinates(lon, lat);

                int temp = Convert.ToInt32(weather.Temperature);
                this.NavigationItem.Title = "The weather for " + weather.City;

                templabel.Text = temp.ToString() + "F";

                descriptiontextfield.BackgroundColor = UIColor.Clear;
                descriptiontextfield.Editable        = false;

                descriptiontextfield.Text = "the current conditions are " + weather.Description;

                emojilabel.Text = SetEmojiBasedOnDescription(descriptiontextfield.Text);

                UIApplication.Notifications.ObserveDidEnterBackground((sender, args) =>
                {
                    Manager.LocationUpdated -= HandleLocationChanged;
                });

                UIApplication.Notifications.ObserveDidBecomeActive((sender, args) =>
                {
                    Manager.LocationUpdated += HandleLocationChanged;
                });

                SetBackgroundGraidentBasedonTemp(this.View, temp);
            }

            else
            {
                Debug.WriteLine("No access to location data");
            }
        }
 private void SetLocationManager(LocationManager p_locationManager)
 {
     locationManager = p_locationManager;
 }