2

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#?

0

1 Answer 1

6

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;
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, this gets me the lat and long perfectly, I really appreciate the help.
Glad it helps, feel free to mark the question as answered by selecting the tick next to the answer. Thanks
Sorry, I worded it horribly and I'm trying to say this more clearly so I'm reposting it. I have a button on my html page that takes the address someone puts in and deals with it to get back the lat long. In a C# file I have the code for the button, which is ending in getting the lat and long into Strings. How can I then display these strings on my html page?
<asp:Button Text="Submit" runat="server" onclick="GetLatLong" ></asp:Button> This is the call in my html page for the method that gets the lat and long
Post that as a new question, showing your markup and button click handler method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.