Take the 2-minute tour ×

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?

share|improve this question
add comment

2 Answers

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();

    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;        

share|improve this answer
add comment
up vote -1 down vote accepted

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.

share|improve this answer
This SELECT statement doesn't work as is and I'm not sure what would fix it \-: –  hippietrail Aug 23 '12 at 19:02
You need to encode the select query and append it to the url. –  SpaceApple Aug 24 '12 at 10:14
Oh I mean it doesn't even work in the YQL console. The escaped double quotes are probably a problem, I'm not sure if {0} is some kind of template? And the final "r" is missing a closing quote. It results in this error: Query syntax error(s) [line 1:41 no viable alternative at character '&amp;amp;#92;',line 1:63 mismatched character ' ' expecting '"']. YQL console link –  hippietrail Aug 24 '12 at 13:17
In the console you need to write out SELECT * FROM geo.placefinder WHERE text="-27,28" and gflags="R" –  SpaceApple Aug 24 '12 at 14:11
add comment

Your Answer


