通过Google可视化进行Fusion Table查询 [英] Fusion Table Query via Google Visualization

查看:141
本文介绍了通过Google可视化进行Fusion Table查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 函数createBoundingBox(){
outputDiv = document.getElementById('outputDiv');
outputDiv.innerHTML ='';
var queryList = [];
queryList.push(SELECT'WEB','NAME','ADDRESS','Lat','Lng','WEB1'FROM);
queryList.push(Table);
queryList.push(WHERE+ where +AND);
queryList.push(ST_INTERSECTS('GEOMETRY',);
queryList.push(RECTANGLE(LATLNG);
queryList.push(sw);
queryList。 push(,LATLNG);
queryList.push(ne);
queryList.push()));
var query = encodeURIComponent(queryList.join(''));
var gvizQuery = new google.visualization.Query(
'http://www.google.com/fusiontables/gvizdata?tq='+ query);

gvizQuery.send(function(response){

numRow = response.getDataTable()。getNumberOfRows();
var datatable = response.getDataTable();


if(datatable& datatable.getNumberOfRows()){
// var linkList = [];

var newLinkList = [ ];




(var i = 0; i< numRow; i ++){
var name = response.getDataTable()。 getValue(i,1);
nameList.push(name);
var address = response.getDataTable()。getValue(i,2);
addressList.push(address);
var latitude = new google.maps.LatLng(response.getDataTable()。getValue(i,3)); alert(latitude)
latitudeList.push(latitude);
var longitude = new google.maps.LatLng(response.getDataTable()。getValue(i,4));
longitudeList.push(longitude);
var newLink = response.getDataTable()。getValue(i,5) ;
newLinkList.push(< a name ='link'id =+'+ i +'+onmouseover ='getId(this)'href =+ newLink +target ='_ blank'> + name +< / a>);



infoContent.push(name+ name +< br> address:+ address);

// var link = response.getDataTable()。getValue(i,0);
// linkList.push(link);


}

names = newLinkList.join(< br>);
outputDiv.innerHTML = numRow +nearby results+ sAddress +< br>< br>;
outputDiv.innerHTML + = names;


}



});


$ / code>

这是查询Fusion中数据的代码表。我想知道为什么经纬度显示为(30.xxx,NaN)和(-97.xxx,NaN),应该是30.xxx和-97.xxx。感谢您的帮助!

解决方案

猜一猜,数据中的第3列是纬度,第4列是经度,对吗?如果是这样,那么你的问题是你正在错误地使用 google.maps.LatLng LatLng 构造函数需要一个(lat,long)对作为参数,即:

  var latLng = new google.maps.LatLng(latitude,longitude); 

,它返回一个LatLng对象。所以,当你这样调用它时:

  var latitude = new google.maps.LatLng(response.getDataTable()。getValue (i,3)); 
var longitude = new google.maps.LatLng(response.getDataTable()。getValue(i,4));

构造函数认为您每次都给它一个没有经度的纬度。你想要做的是这样的:

$ $ $ $ $ $ $ $ $ $ var inputLatitude = response.getDataTable()。getValue(i,3);
var inputLongitude = response.getDataTable()。getValue(i,3);
var latLng = new google.maps.LatLng(inputLatitude,inputLongitude);
latitudeList.push(latLng.lat());
longitudeList.push(latLng.lng());


function createBoundingBox() {
outputDiv = document.getElementById('outputDiv');
outputDiv.innerHTML = '';
var queryList = [];
queryList.push("SELECT 'WEB', 'NAME', 'ADDRESS', 'Lat', 'Lng', 'WEB1' FROM ");
queryList.push(Table);
queryList.push(" WHERE " + where + " AND ");
queryList.push("ST_INTERSECTS('GEOMETRY', ");
queryList.push("RECTANGLE(LATLNG");
queryList.push(sw);
queryList.push(", LATLNG");
queryList.push(ne);
queryList.push("))");
var query = encodeURIComponent(queryList.join(''));
var gvizQuery = new google.visualization.Query(
    'http://www.google.com/fusiontables/gvizdata?tq=' + query);

gvizQuery.send(function(response) {

    numRow = response.getDataTable().getNumberOfRows();
    var datatable = response.getDataTable();


    if (datatable && datatable.getNumberOfRows()) {
     //   var linkList = [];

        var newLinkList = [];




        for (var i = 0; i < numRow; i++) {
            var name = response.getDataTable().getValue(i, 1);
            nameList.push(name);
            var address = response.getDataTable().getValue(i, 2);
            addressList.push(address);
            var latitude = new google.maps.LatLng(response.getDataTable().getValue(i, 3));   alert(latitude)
            latitudeList.push(latitude);
            var longitude = new google.maps.LatLng(response.getDataTable().getValue(i, 4));
            longitudeList.push(longitude);
            var newLink = response.getDataTable().getValue(i, 5);
            newLinkList.push("<a name = 'link' id="+"'" + i + "'" + "onmouseover='getId(this)' href=" + newLink + " target='_blank'>" + name + "</a>");



            infoContent.push("name" + name + "<br>address: "+address);

            //       var link = response.getDataTable().getValue(i, 0);
   //         linkList.push(link);


        }

        names = newLinkList.join("<br>") ;
        outputDiv.innerHTML = numRow+ " results nearby " + sAddress + "<br><br>";
        outputDiv.innerHTML += names;


    }



});

}

This is the code that is querying the data from the Fusion Table. I'm wondering why the Latitude and Longitude are showing up as (30.xxx, NaN) and (-97.xxx, NaN) when it should be just 30.xxx and -97.xxx. Thank you for your help!

解决方案

At a guess, column 3 in your data is latitude and column 4 is longitude, correct? If so, then your problem is that you are using google.maps.LatLng incorrectly. The LatLng constructor expects a (lat, long) pair as the arguments, ie:

var latLng = new google.maps.LatLng(latitude, longitude);

and it returns a LatLng object. So, when you call it like this:

var latitude = new google.maps.LatLng(response.getDataTable().getValue(i, 3));
var longitude = new google.maps.LatLng(response.getDataTable().getValue(i, 4));

the constructor thinks you are giving it a latitude with no longitude each time. What you want to do is this:

var inputLatitude = response.getDataTable().getValue(i, 3);
var inputLongitude = response.getDataTable().getValue(i, 3);
var latLng = new google.maps.LatLng(inputLatitude, inputLongitude);
latitudeList.push(latLng.lat());
longitudeList.push(latLng.lng());

这篇关于通过Google可视化进行Fusion Table查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆