如何根据房间持久性中的最近距离检索数据
how to retrieve data based on the closest distance in room persistance
干草所有..我的android数据库中有一个客户table..我目前正在使用房间持久性,我希望获取我所有的客户数据..但是从一开始就顺序目前离我最近的位置..如何查询我的案例..我当前的纬度是 -7.3530829,我的经度目前是 112.6901788
data in my customers table
customers.address = "Waterpark Boulevard Citraland Area
customers.handphone1 = "0857887328"
customers.latitude = -7.2864881
customers.longitude = 112.6525076
data in my customers table
customers.address = "Nature Conservation Area
customers.handphone1 = "0857887328"
customers.latitude = -7.3571553
customers.longitude = 112.6862058
data in my customers table
customers.address = "Kawasan Taman Pinang
customers.handphone1 = "0857887328"
customers.latitude =
-7.3403807
customers.longitude = 112.6914085
//get Data by Name,,
@Query("SELECT * FROM customers WHERE name = :name")
abstract fun findByName(name:String): MutableList<Customers>
//How to retrieve data based on the closest distance ?
@Query("SELECT ???")
abstract fun findByDistance(mylatitude:Double,mylongitude:Double): MutableList<Customers>
请帮忙查找距离查询..
我通过计算直线距离找到了正确的查询。
@Query("SELECT * FROM customers ORDER BY ABS(latitude - :latitude) + ABS(longitude - :longitude) ASC")
abstract fun findByDistance(latitude:Double,longitude:Double): MutableList<Customers>
也许这可以帮助到和我有同样需求的你..谢谢..
干草所有..我的android数据库中有一个客户table..我目前正在使用房间持久性,我希望获取我所有的客户数据..但是从一开始就顺序目前离我最近的位置..如何查询我的案例..我当前的纬度是 -7.3530829,我的经度目前是 112.6901788
data in my customers table
customers.address = "Waterpark Boulevard Citraland Area
customers.handphone1 = "0857887328"
customers.latitude = -7.2864881
customers.longitude = 112.6525076
data in my customers table
customers.address = "Nature Conservation Area
customers.handphone1 = "0857887328"
customers.latitude = -7.3571553
customers.longitude = 112.6862058
data in my customers table
customers.address = "Kawasan Taman Pinang
customers.handphone1 = "0857887328"
customers.latitude =
-7.3403807
customers.longitude = 112.6914085
//get Data by Name,,
@Query("SELECT * FROM customers WHERE name = :name")
abstract fun findByName(name:String): MutableList<Customers>
//How to retrieve data based on the closest distance ?
@Query("SELECT ???")
abstract fun findByDistance(mylatitude:Double,mylongitude:Double): MutableList<Customers>
请帮忙查找距离查询..
我通过计算直线距离找到了正确的查询。
@Query("SELECT * FROM customers ORDER BY ABS(latitude - :latitude) + ABS(longitude - :longitude) ASC")
abstract fun findByDistance(latitude:Double,longitude:Double): MutableList<Customers>
也许这可以帮助到和我有同样需求的你..谢谢..