【问题标题】:Query between distances in ParseParse中距离之间的查询
【发布时间】:2015-02-26 21:11:23
【问题描述】:

我想使用 GeoPoints 搜索两个给定距离之间的位置。使用当前的 api,我想我可以做出类似这样的伪算法:

query.whereWithinKilometers("directions", GlobalData.ownerGeoPoint, MAXIMUM distance);

减号

query.whereWithinKilometers("directions", GlobalData.ownerGeoPoint, MINIMUM distance);

我怎样才能翻译成真正的代码?

【问题讨论】:

  • 听起来你想在一个甜甜圈形状的区域里找东西。对吗?
  • 是的,danh。

标签: android parse-platform pfquery geopoints


【解决方案1】:

最后我找到了一种使用解析查询的方法。

// Do not want locations further than maxDistance
ParseQuery query = ParseQuery.getQuery("MyData");
query.whereWithinKilometers("location", userGeoPoint, maxDistance);

// Do not want locations closer than minDistance
ParseQuery<ParseObject> innerQuery = ParseQuery.getQuery("MyData");
innerQuery.whereWithinKilometers("location", userGeoPoint, minDistance);
query.whereDoesNotMatchKeyInQuery("objectId", "objectId", innerQuery);

【讨论】:

  • 您能否帮我计算一下地图上可见区域的“最大距离”。
【解决方案2】:

您可能必须拉入从 Parse 到您的应用的最大距离内的所有内容,然后在您的应用内部过滤掉任何比最小值更近的内容。

谢天谢地,Parse 包含一些距离测量作为 PFGeoPoint 的一部分。查看here的三种方法。

  1. distanceInRadiansTo:
  2. distanceInMilesTo:
  3. distanceInKilometersTo:

所以你的伪代码是:

(After you get back everything within the outer radius)

Make a new array (var) called finalList
For i = 0; i < objects.count; i++ {
   var gp: PFGeoPoint = objects[i]
   if gp.distanceInMilesTo:originalGeoPoint >= minimumRadiusInMiles {
      finalList.push(gp)
   }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-16
    • 1970-01-01
    • 1970-01-01
    • 2014-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-07
    相关资源
    最近更新 更多