gpt4 book ai didi

ios - 如何执行 whereKey 以便查询距当前用户____公里远的帖子?

转载 作者:行者123 更新时间:2023-11-30 14:11:11 25 4
gpt4 key购买 nike

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: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];
}

}

关于ios - 如何执行 whereKey 以便查询距当前用户____公里远的帖子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31756263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com