public SelectTownViewModel(CityTown selectedCity)
        {
            XmlCityTownRepository countryRepository = new XmlCityTownRepository();

            SelectedCity = selectedCity;

            ListItemsSource = countryRepository.GetTownList(selectedCity);
        }
        void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
        {
            if (!mIsGeoCoordinateReady)
                return;

            mMainPageViewModel.IsLoading = false;
            mWatcher.Stop();

            System.Diagnostics.Debug.WriteLine("Latitude: " + e.Position.Location.Latitude.ToString("0.000"));
            System.Diagnostics.Debug.WriteLine("Longitude: " + e.Position.Location.Longitude.ToString("0.000"));

            double postionLatitude = e.Position.Location.Latitude;
            double postionLongitude = e.Position.Location.Longitude;

            XmlCityTownRepository countryRepository = new XmlCityTownRepository();
            IList<Town368> townList = countryRepository.GetTownList();

            Town368 location = null;
            double minDistance = 9999999999;
            foreach (Town368 town in townList)
            {
                double distance = Math.Abs(System.Convert.ToDouble(town.Town.Latitude) - postionLatitude) + Math.Abs(System.Convert.ToDouble(town.Town.Longitude) - postionLongitude);
                if (distance < minDistance)
                {
                    System.Diagnostics.Debug.WriteLine("minDistance: " + minDistance);
                    System.Diagnostics.Debug.WriteLine("Town: " + town.Town.Name);
                    location = town;
                    minDistance = distance;
                }
            }

            IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
            settings["forecastTown"] = location.Town;
            settings["forecastCity"] = location.City;
            settings.Save();

            OnLoaded(null, null);
        }
Esempio n. 3
0
        public CityTownViewModel()
        {
            XmlCityTownRepository countryRepository = new XmlCityTownRepository();

            ListItemsSource = countryRepository.GetCountryList();
        }