加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在sqlite android中创建用户定义的函数?

发布时间:2020-12-12 19:00:12 所属栏目:百科 来源:网络整理
导读:我正在开发一个应用程序,我需要为距离创建sqlite函数,我在数据库中有两个字段的纬度和经度,我想在使用该函数的位置附近找到,我已经在iPhone中开发了应用程序,我已经使用了sqlite3_create_function通过调用回调函数,这会给我一个距离. 但问题是:我无法使用an
我正在开发一个应用程序,我需要为距离创建sqlite函数,我在数据库中有两个字段的纬度和经度,我想在使用该函数的位置附近找到,我已经在iPhone中开发了应用程序,我已经使用了sqlite3_create_function通过调用回调函数,这会给我一个距离.

但问题是:我无法使用android在SQLITE中创建函数,有没有人知道使用android从sqlite获取附近位置的更好方法?

另一个问题是SQLITE不支持sin,余弦函数来计算点之间的距离.

解决方法

你好Jignesh,

在我看来,你的问题基本上有两种解决方案.

1.使用javaScript执行这些功能

在javaScript中创建必要的函数,并使用结果更新/查询Sqlite.

JavaScript非常适合三角学;正弦,余弦和正切. JavaScript可以非常快速地计算高级数学问题.

示例:计算以下问题的答案

The sum of the squares of the first ten natural numbers is,1^2 + 2^2 +…
+ 10^2 = 385. The square of the sum of the first ten natural numbers is,(1 + 2 + … + >10)^2 = 55^2 = 3025. Hence the difference between the sum of the squares of the first ten >natural numbers and the square of the sum is 3025 – 385 = 2640. Find the difference >between the sum of the squares of the first one hundred natural numbers and the square of >the sum.

function Problem_6() {
    "use strict";
    var i = 1,ns = 0,sqs = 0;
    do {
        ns += i;
        sqs += i * i;
        i += 1;
    } while (i <= 100);
    return ns * ns - sqs;
}

答案:25164150

这个例子来自Rolando Garza的El blog de rolandog,基于他自己对javaScript全局数学对象的扩展; Math.js.

参考文献:

Mozilla’s JavaScript References for the Global Math Object:

Trigonometry—sine,cosine and tangent with JavaScript,by JJ Gifford.

2. GeoNames Database

GeoNames是一个开源数据库,涵盖了世界上大多数国家,城市和村庄的地理信息,包括纬度和经度以及到其他地理位置的距离.

GeoNames既可以通过JSON API作为Web服务,也可以作为可下载的表使用.

2.1 Query GeoNames through JSON API

示例:查找给定纬度/经度的最近交点

http://api.geonames.org/findNearestIntersectionOSMJSON?lat=37.451u0026amp;lng=-122.18u0026amp;username=demo

{“intersection”:{“street2”:“柯蒂斯街”,“street1”:“Roble Avenue”,“距离”:“0.08”,“highway2”:“住宅”,“highway1”:“住宅”,“lng” “:” – 122.1808166”,“LAT”: “37.4506308”}}

2.2 Downloading GeoNames

在Sqlite中本地存储所需的地理信息.

更多信息:http://www.geonames.org/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读