2

I'm pretty new to google maps and fusion tables. I was wondering if it is possible to return queried information from a fusion table and write it into a page using something like innerHTML. Also, I would like to be able to update a fusion table using a standard HTML form. Is this possible and if so can you point me in the right direction? I've been searching around with no results, but it might just be that I don't know how to pose the question. Let me explain as best I can what I'm looking for:

I have a google map with a kml polyline layer. I would like to be able to enter a query into an HTML form (for instance a range of dates, a feature ID, etc.) or click a line feature that has an ID that corresponds to an ID in a fusion table, and run a query that would return the attribute data for the corresponding table entry. Note that the fusion table has no geocoded information, I am just using it as a spreadsheet (I think I understand that fusion tables are easier to query/access than google spreadsheets, but please correct me if I'm wrong).

The form input is pretty self-explanitory - I would just like to be able to enter some info into a form and create a new row in a fusion table.

Thanks in advance for the help/smackdown (whichever it may be)!

Mike

bluefoot
  • 189
  • 2
  • 11

2 Answers2

4

"I want to be able to write the attribute information into the page below my map (using innerHTML)."

This is definitely possible using the "undocumented" Fusion Table JSNOP API. I've used this approach often. I described it in this answer and posted several examples as well: https://stackoverflow.com/a/9778985/1211981

As Odi explained, updates/inserts from the browser are more complicated.

Community
  • 1
  • 1
Eric Bridger
  • 3,751
  • 1
  • 19
  • 34
1

There are several possible solutions to your use case. I suppose you want to a JavaScript-only solution which runs in the browser with no server side code.

To display data from a Fusion Table on Google Maps you should use the FusionTablesLayer, which makes this task really easy and straightforward. There are good examples from Google, e.g. how to change a query using a form or create custom InfoWindows (which would be the preferred way to show data corresponding to what is clicked on the map). If you don't want to care about authentication, just make your tables public, then it should be easy to adapt the examples to your tables.

Another thing is to write data to Fusion Tables: it's not that easy, because here you must care about authentication, see the OAuth guide for detailed information. But at the moment it is not possible to write data directly from the browser to the Fusion Table. But there is hope: With the new Trusted Tester API you can actually do it, but you have to join this group before you can start.

If you can't / don't want to use the new API, consider the server-side approach that I explained here using a script to relay your requests.

Community
  • 1
  • 1
Odi
  • 6,916
  • 3
  • 34
  • 52
  • Thanks for the quick response! I think I need to be more clear about what it is that I'm looking for. My fusion table contains no geocoded data in it, all it has is attribute data (names of places, dates, comments etc) so I don't want to bring in any new layers to my map, I want to be able to write the attribute information into the page below my map (using innerHTML). I'm not sure if this is even something fusion tables support, I have been exploring this option as an alternative to server-side scripting. – bluefoot Apr 17 '12 at 15:26
  • Oh, then I misunderstood your question, sorry. See the answer of Eric, this provides you with a good example how to query a fusion table by yourself using AJAX and jQuery. I wrote a [JavaScript client library](https://github.com/odi86/GFTPrototype/blob/master/lib/gftlib-js/GftLib.js) for this purpose, you can see it in action in [one of my examples](http://localhost/gft/examples/js/data-print/) (just view the source code). – Odi Apr 17 '12 at 21:56