如何执行whereKey以便查询currentuser离开___ km +的帖子? [英] How to do a whereKey so it querys posts ___ km+ AWAY from currentuser?

查看:112
本文介绍了如何执行whereKey以便查询currentuser离开___ km +的帖子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var limitlocation = 5 as Double

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

目前拥有该功能,但它可以吸引5公里范围内的用户.我怎么做到的,所以要走5公里以上.

解决方案

默认情况下,这种类型的查询仅允许您查询距要查询的geoPoint 100英里以内的geoPoint:

var limitlocation = 5 as Double

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

currently have that but it gets users that are within 5 km. how do i make it so it is 5 km+ AWAY.

By default this type of query will only allow you to query geoPoints that are within 100 miles of the geoPoint you are querying for : https://www.parse.com/docs/ios/guide#geopoints-caveats.

What you can do is filter the results and remove any results that are within 5km.

This is how it would look in objective-c - you'll have to translate this into 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];
    }

}

这篇关于如何执行whereKey以便查询currentuser离开___ km +的帖子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆