title: Querying a fusion table to see if a polygon contains a coordinate
body: <p>Is there a way to determine if a coordinate is inside a fusion table layer?  I tried to do this with a few homegrown methods but around 6% of the locations I’m testing are returning false results. One of the results says that Glasgow is not in Scotland.</p>
  
  <p>Can I query <a href="https://www.google.com/fusiontables/DataSource?docid=1d5LmqKYvkTDxmYK3-9-aQLNz3Z0QAEwqHusAm5w" rel="nofollow">this Fusion Table</a> and ask it if Glasgow is in Scotland? Preferably returning a boolean value.</p>
  
  <ol>
  <li>Glasgow coords: <code>55.855513, -4.252649</code></li>
  <li>Scotland query: <code>Geometry where ‘NAME’ = ‘Scotland’</code></li>
  <li>KML column: <code>Geometry</code></li>
  <li>Fusion Table Id: <code>1d5LmqKYvkTDxmYK3-9-aQLNz3Z0QAEwqHusAm5w</code>  </li>
  </ol>
  
  <p>I think I have to use <code>ST_CONTAINS</code> or <code>ST_INTERSECTS</code> but I'm not sure how, if they work with polygon shapes.</p>
  
  <p><strong>Overall Solution</strong></p>
  
  <p>Using the query in the given answer you can get the name of the polygon using the FusionTablesAPI.</p>
  
  <pre><code>lat = 55.855513
  lng = -4.252649
  table = '1d5LmqKYvkTDxmYK3-9-aQLNz3Z0QAEwqHusAm5w'
  query = "SELECT NAME FROM #{table} WHERE ST_INTERSECTS(geometry, CIRCLE(LATLNG(#{lat}, #{lng}),1))"
  url = "https://www.googleapis.com/fusiontables/v1/query?sql=#{URI.encode(query)}&amp;key=AIzaSyAm9yWCV7JPCTHCJut8whOjARd7pwROFDQ"
  </code></pre>
  
  <p><a href="https://www.googleapis.com/fusiontables/v1/query?sql=SELECT%20NAME%20FROM%201d5LmqKYvkTDxmYK3-9-aQLNz3Z0QAEwqHusAm5w%20WHERE%20ST_INTERSECTS%28geometry,%20CIRCLE%28LATLNG%2855.855513,%20-4.252649%29,1%29%29&amp;key=AIzaSyAm9yWCV7JPCTHCJut8whOjARd7pwROFDQ" rel="nofollow">Here is the output.</a></p>
  
  <p>This is actually a better solution than I set out to find. </p>
  
  <p>Using the code in the the given answer highlights the polygon on a map which is awesome. Also, <code>postgres</code> can be used too as suggested by Dr.Molle in the comments.</p>