Reputation: 563
I'm writing an asp.net program in C# that should take an address, use the google geocoding web service to get back an XML page, and then find the longitude and latitude of that address on the XML page. If I have built the query string (for example http://maps.googleapis.com/maps/api/geocode/xml?address=1000+Fifth+Avenue,+New+York,+NY&sensor=false), how would I go about sending that query and getting back the return XML page in C#?
Upvotes: 2
Views: 4291
Reputation: 4796
Do this;
XmlDocument xDoc = new XmlDocument();
xDoc.Load("http://maps.googleapis.com/maps/api/geocode/xml?address=1000+Fifth+Avenue,+New+York,+NY&sensor=false");
This'll give you your XmlDocument and then you can process this as you wish.
So if you wanted to obtain the lat and long, you could use XPath
var lat = xDoc.SelectSingleNode("/GeocodeResponse/result/geometry/location/lat").InnerText;
var longitude = xDoc.SelectSingleNode("/GeocodeResponse/result/geometry/location/lng").InnerText;
Upvotes: 6