protected virtual void ConfirmResult(BusinessRulesBase rules, JArray addresses) { foreach (JToken address in addresses) { if (((string)(address["components"]["country"])) == "US") { // try enhancing address by verifying it with USPS var serialNo = ((string)(ApplicationServicesBase.Settings("server.geocoding.usps.serialNo"))); var userName = ((string)(ApplicationServicesBase.Settings("server.geocoding.usps.userName"))); var password = ((string)(ApplicationServicesBase.Settings("server.geocoding.usps.password"))); var address1 = ((string)(address["address1"])); if (!(string.IsNullOrEmpty(userName)) && !(string.IsNullOrEmpty(address1))) { var uspsRequest = new StringBuilder("<VERIFYADDRESS><COMMAND>ZIP1</COMMAND>"); uspsRequest.AppendFormat("<SERIALNO>{0}</SERIALNO>", serialNo); uspsRequest.AppendFormat("<USER>{0}</USER>", userName); uspsRequest.AppendFormat("<PASSWORD>{0}</PASSWORD>", password); uspsRequest.Append("<ADDRESS0></ADDRESS0>"); uspsRequest.AppendFormat("<ADDRESS1>{0}</ADDRESS1>", address1); uspsRequest.AppendFormat("<ADDRESS2>{0}</ADDRESS2>", address["address2"]); uspsRequest.AppendFormat("<ADDRESS3>{0},{1},{2}</ADDRESS3>", address["city"], address["region"], address["postalcode"]); uspsRequest.Append("</VERIFYADDRESS>"); using (var client = new WebClient()) { var uspsResponseText = client.DownloadString(("http://www.dial-a-zip.com/XML-Dial-A-ZIP/DAZService.asmx/MethodZIPValidate?input=" + "" + HttpUtility.UrlEncode(uspsRequest.ToString()))); var uspsResponse = new XPathDocument(new StringReader(uspsResponseText)).CreateNavigator().SelectSingleNode("/Dial-A-ZIP_Response"); if (uspsResponse != null) { address["address1"] = uspsResponse.SelectSingleNode("AddrLine1").Value; address["address2"] = uspsResponse.SelectSingleNode("AddrLine2").Value; address["city"] = uspsResponse.SelectSingleNode("City").Value; address["region"] = uspsResponse.SelectSingleNode("State").Value; address["postalcode"] = (uspsResponse.SelectSingleNode("ZIP5").Value + ("-" + uspsResponse.SelectSingleNode("Plus4").Value)); address["components"]["postalcode"] = uspsResponse.SelectSingleNode("ZIP5").Value; address["components"]["postalcodesuffix"] = uspsResponse.SelectSingleNode("Plus4").Value; address["country"] = address["country"].ToString().ToUpper(); } } } } } }
protected override bool Supports(JObject autofill) { var enabled = ApplicationServicesBase.Settings("server.geocoding.google.address"); return((enabled == null) || ((bool)(enabled))); }
protected override string CreateRequestUrl(BusinessRulesBase rules, JObject autofill) { var pb = new List <string>(); // latitude var lat = ((string)(autofill["latitude"])); if (!(string.IsNullOrEmpty(lat))) { pb.Add(lat); } // longitude var lng = ((string)(autofill["longitude"])); if (!(string.IsNullOrEmpty(lng))) { pb.Add(lng); } return(string.Format("https://maps.googleapis.com/maps/api/geocode/json?latlng={0}&key={1}", HttpUtility.UrlEncode(string.Join(",", pb.ToArray()).Replace(" ", "+")), ApplicationServicesBase.Settings("server.geocoding.google.key"))); }
protected virtual string CreateRequestUrl(BusinessRulesBase rules, JObject autofill) { var components = new List <string>(); var pb = new List <string>(); // address 1 var addr1 = ((string)(autofill["address1"])); if (!(string.IsNullOrEmpty(addr1))) { pb.Add(addr1); } // city var city = ((string)(autofill["city"])); if (!(string.IsNullOrEmpty(city))) { pb.Add(city); } // region var region = ((string)(autofill["region"])); if (!(string.IsNullOrEmpty(region))) { pb.Add(region); } // postalcode var postalCode = ((string)(autofill["postalcode"])); if (string.IsNullOrEmpty(postalCode)) { postalCode = ((string)(autofill.GetValue("componentpostalcode", StringComparison.OrdinalIgnoreCase))); } if (!(string.IsNullOrEmpty(postalCode))) { components.Add(("postal_code:" + postalCode)); } // country var country = ((string)(autofill["country"])); if (!(string.IsNullOrEmpty(country))) { if ((country.Length > 2) && (!(string.IsNullOrEmpty(postalCode)) || !(string.IsNullOrEmpty(region)))) { var allCultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures); foreach (var ci in allCultures) { var ri = new RegionInfo(ci.LCID); if (ri.EnglishName.Equals(country, StringComparison.CurrentCultureIgnoreCase) || ri.NativeName.Equals(country, StringComparison.CurrentCultureIgnoreCase)) { country = ri.TwoLetterISORegionName; break; } } } if (country.Length == 2) { components.Add(("country:" + country)); } else { pb.Add(country); } } var requestUrl = string.Format("https://maps.googleapis.com/maps/api/geocode/json?address={0}&key={1}", HttpUtility.UrlEncode(string.Join(",", pb.ToArray()).Replace(" ", "+")), ApplicationServicesBase.Settings("server.geocoding.google.key")); if (components.Count > 0) { requestUrl = string.Format("{0}&components={1}", requestUrl, HttpUtility.UrlEncode(string.Join("|", components.ToArray()).Replace(" ", "+"))); } return(requestUrl); }
protected virtual string CreateRequestUrl(BusinessRulesBase rules, JObject autofill) { // size=512x512&maptype=roadma&markers=size:mid|color:red|San Francisco,CA|Oakland,CA|San Jose,CA&key=737dk343kjfld83lkjfdlk return(string.Format("https://maps.googleapis.com/maps/api/staticmap?size={0}&scale={1}&maptype={2}&zoo" + "m={3}&markers={4}&key={5}", ToSize(rules, autofill), ToScale(rules, autofill), ToMapType(rules, autofill), ToZoom(rules, autofill), ToMarkers(rules, autofill), ApplicationServicesBase.Settings("server.geocoding.google.key"))); }