Elviin Goomez
Elviin Goomez

Reputation: 233

Parse Cloud code query.withinKilometers

(Edit 1)

I'm trying to work with the cloud code and GeoPoint. With the function "query.withinKilometers" I have a pointer to the Location Class but when I try to call the function I get the error "invalid key name". What is the right way to do this? I could not find anything in the documentation, here is a file of the cloud function.

Error: "code":105,"message":"Invalid key name: [object Object]"

here de documentation: http://parseplatform.org/Parse-SDK-JS/api/v1.11.1/Parse.html

Parse.Cloud.define("getCloseFindings", function(request, response){
var query           = new Parse.Query("findings");
var locQuery        = query.include("location");
var LocQuery        = locQuery.get("geoLocation");
var Loc_Lat         = request.params.Latitude;
var Loc_Long        = request.params.Longitude;
var UserLocation    = new Parse.GeoPoint(Loc_Lat,Loc_Long);
var RadiusLocation  = request.params.Radius;

query.equalTo("isDeleted", false);
query.withinKilometers(locQuery, UserLocation, 100);
query.find({
    success: function(results){
        if(results === undefined){
            var response_jsonArr = {
                code : 404,
                message : "Not Found"
            };
            response.success(response_jsonArr);
        }else{
            var jsonArr = [];
            for ( var i = 0; i < results.length; ++i ) {
                var finding_location    = results[i].get("location");
                jsonArr.push({
                    name: results
                });
            }
            response.success(jsonArr);
        }
    }, error: function(error){
        response.error(error);
    }
});

Upvotes: 1

Views: 285

Answers (1)

bluecereal
bluecereal

Reputation: 513

You are passing an object to query.withinKilometers as the first parameter when you should be passing a String. Try using the key from your query.include call instead, like this:

query.withinKilometers("location", userLocation, 100);

Upvotes: 2

Related Questions