//TODO: Re-enable GetGPS for a new or edited address . public async Task <AddressLookup> GetGPS() { var lookup = new AddressLookup(); string address = this.MainAddress().Address1.Trim(); int pos = address.IndexOf("#"); if (pos > 0) { address = address.Substring(0, pos - 1); } var fullAddress = new string[] { HttpUtility.UrlEncode(address.Trim()), HttpUtility.UrlEncode(this.MainAddress().City.Trim()), HttpUtility.UrlEncode(this.MainAddress().State.Trim()), HttpUtility.UrlEncode(this.MainAddress().Zip.Trim()) }; var apiUri = string.Format("?key={0}&address={1}", Config.MapApiKey, string.Join(",", fullAddress)); GoogleGeocoding geo = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri(Config.MapApiBaseUri); var resp = await client.GetAsync(apiUri); if (resp.IsSuccessStatusCode) { geo = await resp.Content.ReadAsAsync <GoogleGeocoding>(); } } if (geo == null || geo.results.Count != 1) { lookup.ErrorMessage = string.Format("Error: {0} Results from Google. Recheck entire address.", geo == null ? 0 : geo.results.Count); return(lookup); } lookup.LatLng = string.Format("{0}, {1}", geo.results[0].geometry.location.lat, geo.results[0].geometry.location.lng); if (geo.results[0].geometry.location_type != "ROOFTOP") { lookup.LocationMessage = string.Format("Google Map API results not exact. Lookup result was {0}", geo.results[0].geometry.location_type); } return(lookup); }
public AddressController() { this.googleGeocoding = new GoogleGeocoding(); }