Frank
Frank

Reputation: 81

Query Fusion Table and display COUNT()

I have a simple question (but I'm not a programmer...)

On http://www.strahlen.org/index.htm I manually enter the numbers of rows that contain a certain string in a Google Fusion table. "454" records in this case for the string "11" (Mineral fair) etc, for each number. Now, manually editing the html source is kind of stupid for this every time I edit the FT...

With the query "https://www.google.com/fusiontables/api/query?sql=SELECT COUNT() FROM 3167783 WHERE title='Mineral fair'" , I get the response "count() 454 ". Where the count is the amount of markers for that string on my Google Maps.

Now, and here comes the stupid part: how do I code my html so that the response "454" gets presented/echoed automagically? To make it more clear: I want the number, the count, to show. As a number. The markers are showing on the maps, that's not the problem. It's a html/js question, but I'm not a coder. I need a snippet of code that can do the trick, but I couldn't find it after hours of google-ing.

Thanks for your help in advance...

Cheers, Frank

Upvotes: 0

Views: 1966

Answers (2)

Eric Bridger
Eric Bridger

Reputation: 3794

I posted an answer to a similar question with sample code at: https://stackoverflow.com/a/9778985/1211981 You need to use the FT JSON API which is "undocumented" but is now officially part of the Trusted Tester's API so I think it's safe to use. Look for the getFTCount() function. It requires jQuery and using a callback so not really simple JS. But I use this approach all the time and the performance is excellent.

Upvotes: 1

javram
javram

Reputation: 2645

I am assuming in your question, that you want the fusionTablesLayer to render the 454 points that match your select statement, so something like this ought to do the trick:

var map = new google.maps.Map(document.getElementById('map-canvas'), 
{
    zoom: 5,
    mapTypeId: google.maps.MapTypeId.ROADMAP
});

var layer = new google.maps.FusionTablesLayer({
    query: {
        select: "title",
        from: 3167783,
        where: "title ='Mineral fair'"
    },
    map: map
});

More information here: https://developers.google.com/maps/documentation/javascript/layers

Upvotes: 0

Related Questions