【问题标题】:How to do a whereKey so it querys posts ___ km+ AWAY from currentuser?如何做一个whereKey,以便查询当前用户距离____公里的帖子?
【发布时间】:2015-07-31 22:43:28
【问题描述】:
var limitlocation = 5 as Double

if let usergeo = currentuser.objectForKey("location") as? PFGeoPoint {
    query.whereKey("location", 
          nearGeoPoint: usergeo, 
          withinKilometers: limitlocation) 
}

目前有,但它会吸引 5 公里范围内的用户。我怎么做到的,所以它距离 5 公里以上。

【问题讨论】:

  • 我不相信目前使用 Parse 的 SDK 可以做到这一点。如果您能够为您的情况设置限制,您可以选择使用范围而不是 withinKilometers 并将其设置为 5 到 X 公里。

标签: ios xcode swift parse-platform


【解决方案1】:

默认情况下,这种类型的查询只允许您查询距您要查询的地理点 100 英里范围内的地理点:https://www.parse.com/docs/ios/guide#geopoints-caveats

您可以做的是过滤结果并删除 5 公里内的任何结果。

这就是它在objective-c中的样子——你必须把它翻译成swift

NSMutalbeArray* mutableObjects = [[NSMutableArray alloc] init];
PFGeoPoint* userGeoPoint = user[@"geoPoint"];
for (PFObject* object in objects) {

    PFGeoPoint* objectGeoPoint = object[@"geoPoint"];
    CLLocation *locA = [[CLLocation alloc] initWithLatitude:userGeoPoint.latitude longitude:userGeoPoint.longitude];
    CLLocation *locB = [[CLLocation alloc] initWithLatitude:objectGeoPoint.latitude longitude:objectGeoPoint.longitude];
    CLLocationDistance distance = [locA distanceFromLocation:locB]; // Distance in meters
    if (distance >= 5000) {
        [mutableObjects add:object];
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多