如何解决CoreData NSPredicate 用于 Swift Core Data 中的算术计算
如何使用 nspredicate 在 swift CoreData 中编写 sql 查询以解决以下问题,我想根据位置模型中的某些字段查找范围内的位置:
以下字段是在查询之前预先计算的。
let CUR_cos_lat = cos(currenLocation.latitude * .pi / 180)
let CUR_sin_lat = sin(currenLocation.latitude * .pi / 180)
let CUR_cos_lng = cos(currenLocation.longitude * .pi / 180)
let CUR_sin_lng = sin(currenLocation.longitude * .pi / 180)
let cos_allowed_distance = cos(2.0 / 6371)
我想使用 nspredicate 在 Swift CoreData 中编写如下查询:
SELECT * FROM position WHERE CUR_sin_lat * sin_lat + CUR_cos_lat * cos_lat * (cos_lng*
CUR_cos_lng + sin_lng * CUR_sin_lng) > cos_allowed_distance;
上述查询中的以下字段已在 CoreData 模型中可用,
- sin_lat
- cos_lat
- cos_lng
- sin_lng
- cos_allowed_distance
这是我尝试过的,但没有返回任何位置,我的表达有什么问题
let predicateS = nspredicate(format: "(%f * trignometry.sinLat + %f) * trignometry.cosLat * (trignometry.cosLng * %f + trignometry.sinLng * %f ) > %f",CUR_sin_lat,CUR_cos_lat,CUR_cos_lng,CUR_sin_lng,cos_allowed_distance)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。