开发者

How do you set queries in Google FusionTables--Especially for text value queries?

I'm trying to query the table to show any location which contains the text that the user has input. So if user searches "Rome", Rome Georgia and Rome Italy are displayed, along with any other location containing "Rome". Pretty basic.

Does searchVal need to be in quotes cause its a string? (Like: 'searchVal'). So the commented out part below would look like: layer.setQuery("SELECT * FROM '853697' WHERE Location CONTAINS '" + searchVal + "'");

Furthermore, I switched this query to work with numbers instead, but I'm still not having any luck...

Here's my code:

   function initTourMap() {

    var nAtlantic = new google.maps.LatLng(31.295359681447383, -53.95838070000002);

    var map = new google.maps.Map(document.getElementById('map_canvas'), {
  开发者_开发百科    center: nAtlantic,
      zoom: 3,
      mapTypeId: 'hybrid'
    });

    var layer = new google.maps.FusionTablesLayer({
      query: {
        select: 'Location',
        from: '853697',
        where: 'Nmbr contains 8',
      },
    });

    $("#submitSearch").click(function(){
        var searchVal = $("#Search").val();
        alert(searchVal);
    //layer.setQuery("SELECT * FROM '853697' WHERE Location CONTAINS searchVal");  //search user's input
        layer.setQuery("SELECT * FROM '853697' WHERE Nmbr CONTAINS 4");
        layer.setMap(map);
    });    

    layer.setMap(map);

//END initTourMap() FUNCTION
}


You can read more about this here: http://code.google.com/apis/maps/documentation/javascript/layers.html#FusionTablesQueries I see a couple of issues in your example. The table id is an integer and should never be quoted. searchVal must be quoted when it's a string, but not quoted when it's a number. CONTAINS is a string operator and will not work with numbers. You can use = or >=, etc. Column names must be quoted only if they contain blanks.

Finally, layer.setQuery() is deprecated and while it still works you should use layer.setOption({query:...}). I've had problems with combining the two methods in a single application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜