問(wèn)題描述
我有問(wèn)題.我想在 android 應(yīng)用程序中獲取谷歌地圖上最近的點(diǎn).不同的點(diǎn)/坐標(biāo)存儲(chǔ)在 sqlite 數(shù)據(jù)庫(kù)中.我必須從他們那里得到最近的 5 個(gè).我正在使用的查詢是:
I've a problem. I want to get the nearest points on google map in android app. Different points/coordinates are stored in sqlite database. And I have to get the nearest 5 from them. The Query I'm using is:
SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 5;
但我收到一個(gè)錯(cuò)誤,即沒(méi)有這樣的功能:acos 存在".它的正確解決方案是什么
But I'm getting an error i.e. "no such function: acos exists". What will be its proper solution
推薦答案
SQLite 默認(rèn)不支持任何三角函數(shù),所以你不能在 SQL 查詢中使用它們.
SQLite doesn't support any trigonometric functions by default, so you can't use them in SQL queries.
您可以獲取坐標(biāo)列表并在應(yīng)用程序代碼中處理它,或者您可以嘗試使用用戶定義的函數(shù)在 SQLite 中公開(kāi) Java 的三角函數(shù)(請(qǐng)參閱 如何在 SQLite 中創(chuàng)建用戶定義函數(shù)?).
You can either fetch the list of coordinates and process it in application code, or you can try and expose Java's trigonometric functions in SQLite with user defined functions (see How can I create a user-defined function in SQLite?).
這篇關(guān)于不存在這樣的 acos 函數(shù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!