9. Querying for the nearest objects (Help)


#1

function queryNearestLocations(){
var client = new Usergrid.Client({
//Initialize your client here.
orgName:"marin",
appName:"sandbox"
});

//Setup your options object here.
//Set the type to landmarks
//Fill in the parameters of the query!
var options = {
    type: "landmarks",
    qs: {"ql": "location within <10000 in meters> of <42.3314>, <-83.0458>"}
};

//Lets create a collection from our query results!
client.createCollection(options, function(error, myLandmarks){
    if(error) {
       $("#response").append("An error occurred."); 
    } else {
        //Iterate through the results of our query.

while(myLandmarks.hasNextEntity()) {
//Use getNextEntity() here to get each result of our query
function getNextEntity(){
var landmark = myLandmarks;
var name = landmark;
$("#response").append("

  • "+name+"
  • ");
    }
    }
    }
    });
    }