首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用融合表图层平移和缩放以显示查询结果

使用融合表图层平移和缩放以显示查询结果
EN

Stack Overflow用户
提问于 2012-02-05 17:33:22
回答 1查看 386关注 0票数 0

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

函数changeMap() {

代码语言:javascript
复制
    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
      }
    });
  }

有人能帮我吗?我将非常感谢你的帮助。

Trebor

EN

回答 1

Stack Overflow用户

发布于 2012-04-19 05:57:43

做你想做的事情绝对是可能的,但这并不容易。在本例中,要平移到的位置由Google Geocoding API使用地址计算得出。但是您的JavaScript代码中并没有真正的地址(即locationColumn的内容)。这取决于您在locationColumn中存储的是什么类型的信息,我认为是某种可以进行地理编码的地址。

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

代码语言:javascript
复制
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 */

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9148224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档