Parse geo-queries always empty

2019-02-19 02:57发布

问题:

Im currently trying to get Parse's geo-query system to work. On my data browser, I have an installation with a key "location" of type geo-point that has a geo-point with latitude 30.27263636013176 and longitude -97.75766807716373 set in it.

However, if I try to query with the following code, I always get "results":[].

curl -X GET \ 
-H "X-Parse-Application-Id: myAppKey" \ 
-H "X-Parse-REST-API-Key: myAPIKey" \ 
-G \ --data-urlencode 'limit=10' \
--data-urlencode 'where={
"location": {
  "$nearSphere": {
    "__type": "GeoPoint",
    "latitude": 30,
    "longitude": -97
  }
}
}' \
https://api.parse.com/1/classes/PlaceObject

Note that the query is running successfully; there are no errors. The problem is the installation I have should come up.

If I change the latitude and longitude in the query to exactly the latitude and longitude shown in the data browser, I still get empty results. What is the reason for this? Is it not possible to query for device installations near a point?

回答1:

The Installation class can't be queried from the client, for good reason. Too much sensitive information is stored in the Installation class to allow querying from a client.

Either move the location property to another class you can query, or query it in a Cloud Function.

You can query it in Cloud Code if you use Parse.Cloud.useMasterKey();, though I strongly recommend using a different class to store the location.



回答2:

Should the url be https://api.parse.com/1/classes/Installation instead of https://api.parse.com/1/classes/PlaceObject ?