从Bing Geocoding服务中提取Lat / Long

时间:2010-12-07 10:32:32

标签: c# xml linq-to-xml geocoding

我正在尝试使用linq to xml提取纬度和经度信息但由于某种原因我的努力失败并且我无法调试linq语句,这里是返回XML的URL:

http://dev.virtualearth.net/REST/v1/Locations/UK/ST104DB?o=xml&key=AsXXdDNPzhinQEhfr9DJe_auOyXAsHr_jF8O0cjGJZDSayU8zedGhy8Vu2PzKTB9

请有人向我展示一个适当的linq语句,用于提取纬度和经度值

由于

1 个答案:

答案 0 :(得分:2)

这是我的 - 我不知道 - 我真的在做什么但是它的第一次尝试

var xml = XDocument.Load(@"c:\temp\geo.xml"); // or from stream or wherever

XNamespace ns = "http://schemas.microsoft.com/search/local/ws/rest/v1";
var points = (from p in xml.Descendants(ns + "Point")
              select new
                      {
                        Lat = (double) p.Element(ns + "Latitude"),
                        Long = (double) p.Element(ns + "Longitude")
                      })
               .ToList();

可能有更好,更安全的方法来做到这一点。

相关问题