Search with GeoCode

Jun 25, 2011 at 3:43 AM

I'm experimenting with LTT's search functionality in the demos, I'm trying to return all results that have a GeoCode associated with them as I see (GeoCode) is one of the parameters that can be specified in a search as follows:

            string geocode = "-104.9230675,39.5485127,500"; //lat,lng,radius
            var queryResults =
             from search in twitterCtx.Search
             where search.Type == SearchType.Search &&
                   search.Query == "LINQ to Twitter" &&
                   search.GeoCode = geocode
             select search;

When I execute this query, I get a '403' Unauthorized error - is this an API issue - will results that don't have a GeoCode specified just be ignored?

Thanks!

Coordinator
Jun 25, 2011 at 5:22 AM

Hi jbcholdings,

A couple issues, but let me give you a tip that can help you and others that might read this post.  If you dig into the exception that occurs, you'll find a TwitterQueryException with a Response property.  L2T populates the Response property with additional information on what went wrong.  Sometimes this Response info is informative and happened to be pretty decent in your case.  Here's what I saw:

1. As is, the radius needs a units indicator of either "mi" for miles or "km" for kilometers.  The Response message was "The within: operator requires distance and units of 'mi' or 'km'".  Here's how I changed the parameter:

string geocode = "-104.9230675,39.5485127,500km"; //lat,lng,radius

As you can see, I just appended km to the radius (aka within).

2. After running that, I received a different error message that indicated your latitude was incorrect.  The response message was "Please provide a latitude between -90 and 90."  On a whim, I switched latitude and longitude, like this:

string geocode = "39.5485127,-104.9230675,500km"; //lat,lng,radius

I don't know if that's in the middle of the ocean or a valid place, but Twitter didn't seem to mind. :)

@JoeMayo