我正在更改 Google 示例模板,以尝试构建一个查询,以查找表中距离用户输入的城市最近的位置。在这个例子中,我只想输出纬度和经度,以及可能是距离用户输入的城市最近的表位置的“id”。首先,我使用 LATITUDE 列作为位置,因为它已在表中被地理编码为两列位置。奇怪的是,当我警告该变量时,它只显示纬度而不是纬度/经度坐标。我认为由于 LATITUDE 充当两列位置,因此它会返回纬度/经度。
因此,当我在输入城市后按下“go”按钮后运行这个简单的查询时:
var queryList = [];
queryList.push("SELECT LATITUDE,LONGITUDE FROM ");
queryList.push(tableid);
然后提醒值,在弹出窗口中,它工作正常:http://greenandtheblue.com/whentoplant/test_query_geocode.html ,从表中提醒经纬度...我希望如此。
但是当我尝试使用 st_distance 时,我没有得到任何表明它有效的建议。
queryList.push("ORDER BY ST_DISTANCE(LATITUDE, LATLNG("+coordinate.lat()+","+coordinate.lng()+")) LIMIT 1");
http://greenandtheblue.com/whentoplant/test_query_geocode_notworking.html
我更喜欢这种查询方法...看起来更简单:
query: {
select: 'LATITUDE',
from: tableid
},
但我从示例中了解到,我需要将第二个查询(当我按下 go 时执行)放入排序数组中,这使得它变得更加复杂。
我希望这是一个足够清楚的问题。感谢您的帮助。
鲥鱼
最佳答案
如果我像这样进行查询:
queryList.push("SELECT STATION,STATION_NAME,ELEVATION,LATITUDE FROM ");
queryList.push(tableid);
//query seems to work when I comment out the line below.
queryList.push("ORDER BY ST_DISTANCE(LATITUDE, LATLNG("+coordinate.lat()+","+coordinate.lng()+")) LIMIT 1");
var query = encodeURIComponent(queryList.join(' '));
var gvizQuery = new google.visualization.Query(
'http://www.google.com/fusiontables/gvizdata?tq=' + query);
gvizQuery.send(function(response) {
var datatable = response.getDataTable();
var header = 'No results';
var content = 'Sorry, no store delivers here.';
if (datatable && (datatable.getNumberOfRows() > 0)) {
header = datatable.getValue(0, 0);
content = datatable.getValue(0, 1)+"<br>Station:"+datatable.getValue(0,0)+"<br>Elevation:"+datatable.getValue(0,2);
}
infoWindow.setContent('<h3>' + header + '</h3>' +
'<p>' + content + '</p>');
infoWindow.setPosition(coordinate);
infoWindow.open(map);
});
它works对我来说。
更改:
var query = encodeURIComponent(queryList.join('')); // empty string
至:
var query = encodeURIComponent(queryList.join(' ')); // single space
关于javascript - 初学融合表查询...两列位置和st_distance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16381584/