Extracting Lat/Long from Bing Geocoding service
I'm trying to extract the latitude and longitude information using linq to xml but for some reason my efforts fail and I can't debug the linq statement, here is the URL that returns the XML:
http://dev.virtualearth开发者_运维知识库.net/REST/v1/Locations/UK/ST104DB?o=xml&key=AsXXdDNPzhinQEhfr9DJe_auOyXAsHr_jF8O0cjGJZDSayU8zedGhy8Vu2PzKTB9
Please could someone show me an appropriate linq statement for extracting the Latitude and Longitude values
Thanks
Here's my I've-no-idea-what-I'm-really-doing-but-it-works first attempt
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();
There's probably better, safer ways to do this.
精彩评论