【问题标题】:Pan and zoom to display the query results by using Fusion Table Layer使用 Fusion Table Layer 平移和缩放以显示查询结果
【发布时间】:2012-02-05 09:33:21
【问题描述】:

我是 Fusion Table Layer 的初学者。我想在此处显示查询结果(平移和缩放):https://developers.google.com/fusiontables/docs/samples/search_and_zoom,但我无法使用 AND 子句对我的函数执行此操作:

函数 changeMap() {

    var dzialka = document.getElementById('dzialka').value;
    var symbol = document.getElementById('symbol').value;
    var where = '';

    if (dzialka) {
      dzialka = dzialka.replace(/'/g, '\\\'');
      where = "'NUMER' CONTAINS IGNORING CASE '" +
          dzialka + "'";
    }

    if (symbol) {
      if (dzialka) {
        where += ' AND ';
      }
      where += "SYMBOL_OG = '" + symbol + "'";
    }

    layer.setOptions({
      query: {
        select: locationColumn,
        from: tableid,
        where: where
      }
    });
  }

有人可以帮助我吗?我会很感激你的帮助。

特雷伯

【问题讨论】:

    标签: javascript google-fusion-tables


    【解决方案1】:

    做自己想做的事肯定是可以的,但没那么容易。在示例中,平移到的位置由Google Geocoding API 使用地址计算得出。但是您的 JavaScript 代码中并没有真正拥有地址(即locationColumn 的内容)。这取决于您在locationColumn 中存储的信息类型,我想这是可以进行地理编码的某种地址。

    因此,您必须将 select 语句直接发送到 Fusion Tables。 Google Fusion Tables 具有可用于此目的的 JSONP 接口。

    var gftUrl = 'http://www.google.com/fusiontables/api/query?';
    var jsonUrlTail = '&jsonCallback=?';
    var query = 'select ' + locationColumn + ' from ' + tableid + ' where ' + where;
    var params = "sql=" + encodeURI(query + jsonUrlTail);
    
    var myCallback = function(data,status) {
        if(status !== 'success') {
            window.alert('Call to Google Fusion Tables failed: ' + status);
            return;
        }
        var address = data.table.rows[0][0];
    
        /* start code from google example */
        geocoder.geocode({
        address: address
        }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          map.setCenter(results[0].geometry.location);
          map.setZoom(10);
    
          // OPTIONAL: run spatial query to find results within bounds.
          var sw = map.getBounds().getSouthWest();
          var ne = map.getBounds().getNorthEast();
          var where = 'ST_INTERSECTS(' + locationColumn +
              ', RECTANGLE(LATLNG' + sw + ', LATLNG' + ne + '))';
          layer.setOptions({
            query: {
              select: locationColumn,
              from: tableId,
              where: where
            }
          });
        } else {
          window.alert('Address could not be geocoded: ' + status);
        }
        });
        /* end code from google example */
    }
    
    var jqxhr = $.post(gftUrl, params, myCallback, "jsonp"); /* jsonp parameter is very important */
    

    在本例中,我使用jQuery 表示$.post function

    【讨论】:

    • 查看this answer 的一个非常相似的问题。这使用了 Google Visualization API,可能是一个更简单的解决方案。
    猜你喜欢
    • 2015-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多