public List<GeoSok.EniroResult> FindInEniro (string address) { List<GeoSok.EniroResult> resList = new List<GeoSok.EniroResult>(); WebRequest w = WebRequest.Create("http://kartor.eniro.se//query?" + "mop=aq" + "&mapstate=" + "&what=map_adr" + "&geo_area=" + HttpUtility.UrlEncode(address, Encoding.GetEncoding("Windows-1252")) + "&stq=0" + "&pis=0" + "&tpl=map_ajax_map_adr" + "&ajax_get_cache=" ); StreamReader inp = new StreamReader(w.GetResponse().GetResponseStream(), Encoding.GetEncoding(1252)); string fullResponse = inp.ReadToEnd(); string[] responseB; if (fullResponse.Contains("selectAddress")) { Regex re = new Regex(@"selectAddress\((.+?)\)", RegexOptions.Multiline | RegexOptions.IgnoreCase); MatchCollection matches = re.Matches(fullResponse); foreach (Match match in matches) { string[] responseA = match.Value.Split(new string[] { "," }, StringSplitOptions.None); EniroResult res = new EniroResult(); responseB = responseA[3].Split(new string[] { ";" }, StringSplitOptions.None); res.City = responseB[7]; res.Code = responseB[6]; res.Municipality = responseB[17]; res.Street = responseB[3]; res.Number = responseB[4]; double parseResult = 0; double.TryParse(responseB[12], NumberStyles.Float | NumberStyles.AllowDecimalPoint, CultureInfo.GetCultureInfo("en-US").NumberFormat, out parseResult); res.Lon = parseResult; parseResult = 0; double.TryParse(responseB[13], NumberStyles.Float | NumberStyles.AllowDecimalPoint, CultureInfo.GetCultureInfo("en-US").NumberFormat, out parseResult); res.Lat = parseResult; resList.Add(res); } } else { EniroResult res = new EniroResult(); string[] responseA = fullResponse.Split(new string[] { "!_!" }, StringSplitOptions.None); string responsDecoded = HttpUtility.UrlDecode(responseA[3], Encoding.GetEncoding(1252)); responseB = responsDecoded.Split(new string[] { ";" }, StringSplitOptions.None); res.City = responseB[7]; res.Code = responseB[6]; res.Municipality = responseB[17]; res.Street = responseB[3]; res.Number = responseB[4]; double parseResult = 0; double.TryParse(responseB[12], NumberStyles.Float | NumberStyles.AllowDecimalPoint, CultureInfo.GetCultureInfo("en-US").NumberFormat, out parseResult); res.Lon = parseResult; parseResult = 0; double.TryParse(responseB[13], NumberStyles.Float | NumberStyles.AllowDecimalPoint, CultureInfo.GetCultureInfo("en-US").NumberFormat, out parseResult); res.Lat = parseResult; resList.Add(res); } return resList; }
public List <GeoSok.EniroResult> FindInEniro(string address) { List <GeoSok.EniroResult> resList = new List <GeoSok.EniroResult>(); WebRequest w = WebRequest.Create("http://kartor.eniro.se//query?" + "mop=aq" + "&mapstate=" + "&what=map_adr" + "&geo_area=" + HttpUtility.UrlEncode(address, Encoding.GetEncoding("Windows-1252")) + "&stq=0" + "&pis=0" + "&tpl=map_ajax_map_adr" + "&ajax_get_cache=" ); StreamReader inp = new StreamReader(w.GetResponse().GetResponseStream(), Encoding.GetEncoding(1252)); string fullResponse = inp.ReadToEnd(); string[] responseB; if (fullResponse.Contains("selectAddress")) { Regex re = new Regex(@"selectAddress\((.+?)\)", RegexOptions.Multiline | RegexOptions.IgnoreCase); MatchCollection matches = re.Matches(fullResponse); foreach (Match match in matches) { string[] responseA = match.Value.Split(new string[] { "," }, StringSplitOptions.None); EniroResult res = new EniroResult(); responseB = responseA[3].Split(new string[] { ";" }, StringSplitOptions.None); res.City = responseB[7]; res.Code = responseB[6]; res.Municipality = responseB[17]; res.Street = responseB[3]; res.Number = responseB[4]; double parseResult = 0; double.TryParse(responseB[12], NumberStyles.Float | NumberStyles.AllowDecimalPoint, CultureInfo.GetCultureInfo("en-US").NumberFormat, out parseResult); res.Lon = parseResult; parseResult = 0; double.TryParse(responseB[13], NumberStyles.Float | NumberStyles.AllowDecimalPoint, CultureInfo.GetCultureInfo("en-US").NumberFormat, out parseResult); res.Lat = parseResult; resList.Add(res); } } else { EniroResult res = new EniroResult(); string[] responseA = fullResponse.Split(new string[] { "!_!" }, StringSplitOptions.None); string responsDecoded = HttpUtility.UrlDecode(responseA[3], Encoding.GetEncoding(1252)); responseB = responsDecoded.Split(new string[] { ";" }, StringSplitOptions.None); res.City = responseB[7]; res.Code = responseB[6]; res.Municipality = responseB[17]; res.Street = responseB[3]; res.Number = responseB[4]; double parseResult = 0; double.TryParse(responseB[12], NumberStyles.Float | NumberStyles.AllowDecimalPoint, CultureInfo.GetCultureInfo("en-US").NumberFormat, out parseResult); res.Lon = parseResult; parseResult = 0; double.TryParse(responseB[13], NumberStyles.Float | NumberStyles.AllowDecimalPoint, CultureInfo.GetCultureInfo("en-US").NumberFormat, out parseResult); res.Lat = parseResult; resList.Add(res); } return(resList); }