如何执行whereKey以便查询currentuser离开___ km +的帖子? [英] How to do a whereKey so it querys posts ___ km+ AWAY from currentuser?
问题描述
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: 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
这篇关于如何执行whereKey以便查询currentuser离开___ km +的帖子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!var limitlocation = 5 as Double
if let usergeo = currentuser.objectForKey("location") as? PFGeoPoint {
query.whereKey("location",
nearGeoPoint: usergeo,
withinKilometers: limitlocation)
}
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];
}
}