From b5b860501e6a15ee04b3fcc9ae7cc5a0dc9457ef Mon Sep 17 00:00:00 2001 From: Gustavo Martin Date: Sun, 6 Jul 2014 18:57:42 +0200 Subject: [PATCH] Retrieve city and country from location. --- .../WeatherInformation/WeatherInformation/App.xaml | 3 - .../WeatherInformation/MainPage.xaml | 6 +- .../WeatherInformation/MapPage.xaml | 6 +- .../WeatherInformation/MapPage.xaml.cs | 31 +++++++- .../Resources/AppResources.Designer.cs | 45 +++++++++++ .../Resources/AppResources.es.xlf | 25 +++++++ .../Resources/AppResources.qps-ploc.xlf | 25 +++++++ .../WeatherInformation/Resources/AppResources.resx | 20 +++++ .../WeatherInformation/SettingsPage.xaml | 86 +++++++++++++--------- 9 files changed, 200 insertions(+), 47 deletions(-) diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml index d6d3d13..525c2cd 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml +++ b/WindowsPhone/WeatherInformation/WeatherInformation/App.xaml @@ -10,9 +10,6 @@ - diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml index 79e4893..69742f9 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml +++ b/WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml @@ -49,8 +49,7 @@ - - + @@ -81,8 +80,7 @@ - - + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml index 04fc57f..9c3e841 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml +++ b/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml @@ -18,13 +18,13 @@ - + - - + + diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml.cs b/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml.cs index 56622c3..e6e012e 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml.cs @@ -14,6 +14,8 @@ using System.Windows.Shapes; using System.Windows.Media; using Microsoft.Phone.Maps.Controls; using WeatherInformation.Resources; +using System.Globalization; +using Microsoft.Phone.Maps.Services; namespace WeatherInformation { @@ -73,6 +75,11 @@ namespace WeatherInformation ); GeoCoordinate myGeoCoordinate = CoordinateConverter.ConvertGeocoordinate(geoposition.Coordinate); + ReverseGeocodeQuery myReverseGeocodeQuery = new ReverseGeocodeQuery(); + myReverseGeocodeQuery.GeoCoordinate = myGeoCoordinate; + myReverseGeocodeQuery.QueryCompleted += QueryCompletedCallback; + myReverseGeocodeQuery.QueryAsync(); + // Create a small circle to mark the current location. Ellipse myCircle = new Ellipse(); myCircle.Fill = new SolidColorBrush(Colors.Blue); @@ -97,7 +104,7 @@ namespace WeatherInformation this.mapWeatherInformation.Layers.Add(myLocationLayer); _settings["CurrentLatitude"] = myGeoCoordinate.Latitude; - _settings["CurrentLongitude"] = myGeoCoordinate.Longitude; + _settings["CurrentLongitude"] = myGeoCoordinate.Longitude; } catch (Exception ex) { @@ -121,6 +128,28 @@ namespace WeatherInformation } } + + private void QueryCompletedCallback(object sender, QueryCompletedEventArgs> eventData) + { + if (eventData.Cancelled) + { + // Be careful!!! If you throw exception from this point your program will finish with "Unhandled Exception". + return; + } + + Exception errorException = eventData.Error; + if (errorException == null) + { + if (eventData.Result.Count > 0) + { + MapAddress address = eventData.Result[0].Information.Address; + string cityCountry = String.Format(CultureInfo.InvariantCulture, "{0}, {1}", address.City, address.Country); + this.LocationTextCityCountry.Text = cityCountry; + } + } + } + + public static class CoordinateConverter { public static GeoCoordinate ConvertGeocoordinate(Geocoordinate geocoordinate) diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs index 3b12d42..3ba14ae 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.Designer.cs @@ -115,6 +115,42 @@ namespace WeatherInformation.Resources { } /// + /// Busca una cadena traducida similar a City, country. + /// + public static string LocationPageSubTitle { + get { + return ResourceManager.GetString("LocationPageSubTitle", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a Pick your location. + /// + public static string LocationPageTitle { + get { + return ResourceManager.GetString("LocationPageTitle", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a current. + /// + public static string MainPageCurrentHeader { + get { + return ResourceManager.GetString("MainPageCurrentHeader", resourceCulture); + } + } + + /// + /// Busca una cadena traducida similar a forecast. + /// + public static string MainPageForecastHeader { + get { + return ResourceManager.GetString("MainPageForecastHeader", resourceCulture); + } + } + + /// /// Busca una cadena traducida similar a Location autodetection seems to be disabled in your phone. /// public static string NoticeErrorLocationAutodetection { @@ -214,6 +250,15 @@ namespace WeatherInformation.Resources { } /// + /// Busca una cadena traducida similar a settings. + /// + public static string SettingsPageHeaderSettings { + get { + return ResourceManager.GetString("SettingsPageHeaderSettings", resourceCulture); + } + } + + /// /// Busca una cadena traducida similar a Temperature units. /// public static string SettingsTemperatureUnitsHeader { diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf index f413a74..f75279e 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.es.xlf @@ -97,6 +97,31 @@ ºF ºF + + City, country + City, country + Subtitle in location page + + + Pick your location + Pick your location + Title in location page + + + forecast + forecast + Forecast header in main page + + + settings + settings + Header settings in settings page + + + current + current + Current header in main page + ºC ºC diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf index d4361fe..5b5e6b7 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.qps-ploc.xlf @@ -82,6 +82,31 @@ ºF ºF + + City, country + City, country + Subtitle in location page + + + Pick your location + Pick your location + Title in location page + + + forecast + forecast + Forecast header in main page + + + settings + settings + Header settings in settings page + + + current + current + Current header in main page + ºC ºC diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx index 39ab410..9cd670a 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx +++ b/WindowsPhone/WeatherInformation/WeatherInformation/Resources/AppResources.resx @@ -204,4 +204,24 @@ ºF + + City, country + Subtitle in location page + + + Pick your location + Title in location page + + + current + Current header in main page + + + forecast + Forecast header in main page + + + settings + Header settings in settings page + \ No newline at end of file diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/SettingsPage.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/SettingsPage.xaml index 5de48e9..09c758b 100644 --- a/WindowsPhone/WeatherInformation/WeatherInformation/SettingsPage.xaml +++ b/WindowsPhone/WeatherInformation/WeatherInformation/SettingsPage.xaml @@ -29,48 +29,62 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + + + + + + - \ No newline at end of file -- 2.1.4