首页 > 解决方案 > 如何在android的sqlite查询中使用sqrt函数

问题描述

我有这个代码:

// select all venues where distance to theme is less than 1km
@Query("SELECT * FROM Venue WHERE SQRT(((lat-:lat)*(lat-:lat))+((lng-:lng)*(lng-:lng)))<1000.0 ORDER BY distance LIMIT 30 OFFSET :offset")
fun getVenues(lat: Double, lng: Double, offset: Int): Flow<List<Venue>>

但我面临这个错误:

2021-02-23 00:38:51.419 30376-30510 E/SQLiteLog: (1) no such function: SQRT

在 android sqlite 中使用 SQRT 我应该怎么做?

标签: javaandroidsqlitekotlinandroid-room

解决方案


让它平方lat*lat+lon*lon < 1000000.0(1000 * 1000)


推荐阅读