在Android SDK中解析不在PushQuery中运行的GeoPoint查询

时间:2015-12-07 10:58:58

标签: android parse-platform

我正在尝试从设备本身发送地理位置通知。这是我的代码。

ParseQuery pushQuery = ParseInstallation.getQuery();
pushQuery.whereNear("currentLoc", parseGeoPoint);

ParsePush push = new ParsePush();
push.setQuery(pushQuery); // Set our Installation query
push.setMessage("geo push");
push.sendInBackground();

我已经从服务添加了currentLoc和testText属性,它在解析控制台中显示。代码如下。

ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("currentLoc", parseGeoPoint);
installation.put("testText", "text");
installation.saveInBackground();

现在,如果我在查询中使用pushQuery.whereEqualTo("testText", "texto");而不是pushQuery.whereNear("currentLoc", parseGeoPoint);,则会触发通知。

但是当与whereWithinwhereNear查询一起使用时,它会失败并解析推送控制台会产生以下错误

ERROR:
Unable to execute query: error processing query:     ns=appdata1109.app_ded5349f-37a1-4227-a4cc-62eccd9f8a07:_Installation limit=0 skip=0 Tree: GEONEAR field=currentLoc maxdist=1.79769e+308 isNearSphere=1 Sort: {} Proj: {} planner returned error: unable to find index for $geoNear query

1 个答案:

答案 0 :(得分:0)

使用whereWithinMiles

这样做
  

location课程中不需要额外的字段installation   可以使用内部查询并从User

获取位置
// Find users near a given location
ParseQuery userQuery = ParseUser.getQuery();
userQuery.whereWithinMiles("location", stadiumLocation, 1.0) //1.0 is radius in miles

// Find devices associated with these users
ParseQuery pushQuery = ParseInstallation.getQuery();
pushQuery.whereMatchesQuery("user", userQuery);

// Send push notification to query
ParsePush push = new ParsePush();
push.setQuery(pushQuery); // Set our Installation query
push.setMessage("Free hotdogs at the Parse concession stand!");
push.sendInBackground();