1 using Microsoft.Phone.Maps.Services;
3 using System.Collections.Generic;
4 using System.Device.Location;
5 using WeatherInformation.Resources;
7 namespace WeatherInformation.Model
11 public interface IReverseGeoCode
13 void OnCompletedReverseGeoCode(GeoCoordinate geoCoordinate, string city, string country);
16 public IReverseGeoCode Page { get; set; }
17 public GeoCoordinate CoorDinate { get; set; }
19 public void DoReverseGeocode(GeoCoordinate geoCoordinate)
21 var currentReverseGeocodeQuery = new ReverseGeocodeQuery();
22 currentReverseGeocodeQuery.GeoCoordinate = geoCoordinate;
23 currentReverseGeocodeQuery.QueryCompleted += QueryCompletedCallback;
24 currentReverseGeocodeQuery.QueryAsync();
27 private void QueryCompletedCallback(object sender, QueryCompletedEventArgs<IList<MapLocation>> eventData)
29 // Commenting out because I have to disable progress dialog even if the async task was cancelled.
30 //if (eventData.Cancelled)
32 // // Be careful!!! If you throw exception from this point your program will finish with "Unhandled Exception".
36 ReverseGeocodeQuery reverseGeocodeQuery = sender as ReverseGeocodeQuery;
39 var city = AppResources.DefaultCity;
40 var country = AppResources.DefaultCountry;
42 Exception errorException = eventData.Error;
43 if (errorException == null)
45 if (eventData.Result.Count > 0)
47 if (eventData.Result[0].Information != null
48 && eventData.Result[0].Information.Address != null)
50 var address = eventData.Result[0].Information.Address;
51 city = string.IsNullOrEmpty(address.City) ? AppResources.DefaultCity : address.City;
52 country = string.IsNullOrEmpty(address.Country) ? AppResources.DefaultCountry : address.Country;
59 Page.OnCompletedReverseGeoCode(reverseGeocodeQuery.GeoCoordinate, city,country);