Parse 쿼리를 작성하여 입력 된 GeoPoint에 가장 가까운 GeoPoint가있는 Parse 객체를 가져 오는 데 문제가 있습니다. 현재 코드는 가장 최근에 생성 된 객체를 반환하는 것으로 보입니다.클라우드 쿼리를 분석하여 가장 가까운 GeoPoint가있는 객체를 가져옵니다.
코드 :
// check Parse for infections around passed GeoPoint
Parse.Cloud.define("InfectionCheck_BETA", function(request, response) {
var returnCount;
var geoPoint = request.params.geoPoint;
var query = new Parse.Query("InfectedArea");
query.withinMiles("centerPoint", geoPoint, 1); // check for infections within one mile
Parse.Promise.as().then(function() {
// query for count of infection in area, this is how we get severity
return query.count().then(null, function(error) {
console.log('Error getting InfectedArea. Error: ' + error);
return Parse.Promise.error(error);
});
}).then(function(count) {
if (count <= 0) {
// no infected areas, return 0
response.success(0);
}
returnCount = count;
return query.first().then(null, function(error) {
console.log('Error getting InfectedArea. Error: ' + error);
return Parse.Promise.error(error);
});
}).then(function(result) {
// we have the InfectedArea in question, return an array with both
response.success([returnCount, result]);
}, function(error) {
response.error(error);
});
});
내가 원하는 것은 centerPoint
키에 가장 가까운 GeoPoint의 가진 개체를 반환하는 최초의() 쿼리입니다.
나는 query.near("centerPoint", geoPoint)
과 query.limit(1)
을 추가하지 않으려 고 시도했다.
가장 가까운 GeoPoints를 기준으로 정렬하여 반환 할 수있는 whereKey:nearGeoPoint:withinMiles:
을 호출하는 iOS PFQueries를 보았습니다. 이처럼 작동하는 JavaScript가 있습니까?
'query.withinMiles'를 유지하면서 이전에 시도했지만 작동하지 않았습니다. 그러나 1 마일 이내에 지정해야합니다. 이것이 작동한다면, 나는'query.withinMiles'에 대한 카운트 쿼리를 할 수 있었고, 그 후에 카운트가> 0 일 때'query.near'를 가진 별도의 쿼리를 할 수 있었다고 생각합니다. ... –
[http] [http] : //chat.stackoverflow.com/rooms/61287/parse-com)? – Dehli
여전히 위의 코드에서 작동하지 않았습니다. 토론하기 위해 링크로 이동했습니다. –