问题描述
如何使用 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 (将#修改为@)