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

前端之家收集整理的这篇文章主要介绍了在sqlite android中创建用户定义的函数?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在开发一个应用程序,我需要为距离创建sqlite函数,我在数据库中有两个字段的纬度和经度,我想在使用该函数的位置附近找到,我已经在iPhone中开发了应用程序,我已经使用了sqlite3_create_function通过调用回调函数,这会给我一个距离.

但问题是:我无法使用androidsqlITE中创建函数,有没有人知道使用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.451\u0026amp;lng=-122.18\u0026amp;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/

猜你在找的Sqlite相关文章