Question

How would I query to get a country's name using the Latitude and Longitude positions using YQL? Or better could I be pointed to find out the table's columns?

Was it helpful?

Solution 2

The answer I was looking for was :

SELECT * FROM geo.placefinder WHERE text=\"{0}\" and gflags=\"r

Text is the latitude and longitude e.g. -27,28

This will return a xml with country's information.

OTHER TIPS

The above query does work, but let me take you through all the steps.

Constructing the url query to yahoo and creating a request.

string url = string.Format("http://query.yahooapis.com/v1/public/yql?q={0}", HttpUtility.UrlEncode("SELECT * FROM geo.placefinder WHERE text=\"-27,28\" and gflags=\"r\""));
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";

Getting the response data:

using (WebResponse response = request.GetResponse())
{
    XmlDocument doc = new XmlDocument();
    doc.Load(response.GetResponseStream());

    geo.CountryName = doc.SelectSingleNode("./query/results/Result/country").InnerText;
    geo.AlphaCode = doc.SelectSingleNode("./query/results/Result/countrycode").InnerText;
    geo.City = doc.SelectSingleNode("./query/results/Result/city").InnerText;
    geo.State = doc.SelectSingleNode("./query/results/Result/state").InnerText;        

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top