- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
private string ExtractNodeValue(string text, string nodeName)
{
string result = string.Empty;
int slength = ("<" + nodeName + ">").Length;
int sindex = text.IndexOf("<" + nodeName + ">");
int eindex = text.IndexOf("</" + nodeName + ">");
if (sindex > 0 && eindex > 0)
result = text.Substring(sindex + slength, eindex - sindex - slength);
return result;
}
string request = string.Format("http://maps.google.com/maps/geo?ll={0},{1}&hl=en&output=xml&key=abcdefg", location.latitude, location.longitude);
Logger.Log(request);
HttpWebRequest httprequest = (HttpWebRequest)WebRequest.Create(request);
WebResponse responce = httprequest.GetResponse();
Stream str = responce.GetResponseStream();
XmlTextReader reader = new XmlTextReader(str);
reader.XmlResolver = null;
XmlDocument doc = new XmlDocument();
doc.Load(reader);
str.Close();
reader.Close();
XmlNodeList listResponse = doc.ChildNodes[1].ChildNodes[0].ChildNodes;
foreach (XmlNode nodePlace in listResponse)
{
if (nodePlace.Name == "Placemark")
{
string text = nodePlace.InnerXml;
string Country = ExtractNodeValue(text, "CountryName");
if ((this.DataContext.Countries.Count(x => x.Name == location.countryName) == 0 || string.IsNullOrWhiteSpace(location.countryName)) &&
!string.IsNullOrWhiteSpace(Country))
{
location.countryName = Country;
}
string Region = ExtractNodeValue(text, "AdministrativeAreaName");
if (this.DataContext.States.Count(x => x.AlphaCode == location.region || x.Name == location.region) == 0 &&
!string.IsNullOrWhiteSpace(Region))
{
location.region = Region;
}
string City = ExtractNodeValue(text, "LocalityName");
if (this.DataContext.Cities.Count(x => x.Name == location.city) == 0 &&
!string.IsNullOrWhiteSpace(City))
{
location.city = City;
}
break;
}
}
mangyst 04.10.2012 17:16 # 0
3.14159265 04.10.2012 20:42 # +3
К тому же совсем нет LINQ.
http://msdn.microsoft.com/en-us/library/bb387098.aspx