0

输入地理时,我已经为我的点保存了纬度和经度。我创建了自定义 api,并且可以通过此代码从最近的点检索点:

exports.get = function(request, response) {
    var lat = request.query.latitude.replace(",",".");
    var lng = request.query.longitude.replace(",",".");
    var limit = +request.query.limit;
    if (!limit) limit = 20;
    console.log('Filtr: lat - %s, lng - %s, limit - %s', lat, lng, limit);
    var mssql = request.service.mssql;
    var queryString = "SELECT TOP (?) id, title, description, category, city, street, price, startdate, enddate, location.Lat latitude, location.Long longitude, location.STDistance(geography::Point(?, ?, 4326)) AS distance FROM Action ORDER BY distance"
    mssql.query(queryString, [limit, lat, lng], {
        success: function(results) {
            request.respond(statusCodes.OK, results);
        }
    });
};

但我想检索所有积分,但我不知道该怎么做。现在,当我刚刚在脚本操作中读取时:

function read(query, user, request) {
    request.execute();
}

我在我的对象中得到了这个:

"location":{
"0":230,
"1":16,
"2":0,
"3":0,
"4":1,
"5":12,
"6":67,
"7":203,
"8":186,
"9":127,
"10":44,
"11":190,
"12":72,
"13":64,
"14":70,
"15":64,
"16":133,
"17":35,
"18":72,
"19":169,
"20":48,
"21":64,
"length":22
},

我试图从自定义 api 修改 sql 脚本以应用于读取操作,但我不知道如何更改读取操作脚本中的查询。执行请求后,我试图成功,但为时已晚。任何人都可以帮助我吗?

4

1 回答 1

1

我找到了解决我的问题的方法:

function read(query, user, request) {
  var queryString = "SELECT id, title, description, category, city, street, price, startdate, enddate, location.Lat latitude, location.Long longitude FROM Action";   
  mssql.query(queryString, { 
                success: function(results) { 
                     request.respond(statusCodes.OK, results); 
                } 
          }); 
}

在我问这个问题之前,我尝试了这个作为第一个选项,但我用这条线尝试了它:

var mssql = request.service.mssql;

但后来我发现没有这一行的例子,仍然有 mssql 对象,它正在工作。

于 2013-09-19T14:34:23.357 回答