I am trying to use geoname's services to get the latitude and longitude from ZipCode, but all the times it felt down. i couldn't get the connection.
it is just waiting for localhost and finally it felt down on this step
var webResponse = (HttpWebResponse)request.GetResponse();
WebException was unhandle
this is my complete function
public string LookupCoordinates(string Zip, string Country)
{
string Lat = "";
string Lon = "";
string PostUrl = "http://ws.geonames.org/postalCodeSearch?postalcode=" + Zip + "&maxRows=10&country=" + Country;
var request = WebRequest.Create(PostUrl);
var webResponse = (HttpWebResponse)request.GetResponse();
if (webResponse.StatusCode == HttpStatusCode.OK)
{
StreamReader sr = new StreamReader(webResponse.GetResponseStream());
string Result = sr.ReadToEnd().Trim();
if (Result != "")
{
// Load the response into an XML doc
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(Result);
// Navigate to latitude node
XmlNodeList name = xdoc.GetElementsByTagName("lat");
if (name.Count > 0)
{
Lat = name[0].InnerText;
}
// Navigate to longitude node
name = xdoc.GetElementsByTagName("lng");
if (name.Count > 0)
{
Lon = name[0].InnerText;
}
}
}
return (Lat + "," + Lon);
}