English 中文(简体)
计算Kallite两点之间的距离
原标题:Calculate distance between two points directly in SQLite

在我的网络/MySQL申请中,我有这样的东西,在两点之间保持距离:

6371 * acos(cos(radians(-19.83996)) * cos(radians(lat)) * cos(radians(-43.94910) - radians(lng)) + sin(radians(-19.83996)) * sin(radians(lat)))

但是,我用Kalk进行了测试,这些数学功能(联邦、宇宙、rad、 sin)并不存在。 是否对我来说,可以直接计算数据库中的距离?

然而,我有一份应用文件,使用http://www.thismuchiknow.co.uk/?p=71” conf=“noretinger”>,这一计算方法是: 完全可行,但现在我需要在数据库中以安乐文申请进行同样的查询。

提前感谢。

<>>>>>

我有9 000个点来计算距离,并找到一个点附近的5个地点。

最佳回答

在这方面,我要做的是:

回答。 措施a(这是有待改进的任意价值) 周围的面积为2千米,并具有东西/北/南界限的数值。

对该广场内的分子提出质询。 这是一件轻而易举的事,你刚才不得不这样做。

select * from points where lat between ? and ? and lon between ? and ?

取得你的结果。 成果不够(显然不到5项,但我要说的是,有两倍是肯定的)。 太多(即100多个),再次尝试少半径。

Once you have enough, load them, make sure all 5 elements you need are not only in the Xkm wide square, but also in the Xkm radius circle (to avoid having a potential closer element not detected by the previous approximation).

Another approach

只有在您的某一点与你所寻求的点相对接近时,才会有效。

测量一个平地的面积。 在接近你的时候,你可以考虑一下相对、lon和距离之间的直线关系。 这使你能够提出简单限定的请求。 (倍增和增)。 同样,为了在“四方”要求之后进行适当的计算,选择了一点点。

问题回答

在您的表格中插入 co_lat_rad,sin_lat_rad,cos_lon_rad,sin_lon_rad

contentValues.put("cos_lat_rad", Math.cos(deg2rad(latitude)));
contentValues.put("sin_lat_rad", Math.sin(deg2rad(latitude)));
contentValues.put("cos_lon_rad", Math.cos(deg2rad(longitude)));
contentValues.put("sin_lon_rad", Math.sin(deg2rad(longitude)));

学历

public static double deg2rad(double deg) {
    return (deg * Math.PI / 180.0);
}

问 题,距离

 Cursor c=database.dis(String.valueOf(Math.cos((double) distance / (double) 6380)), Math.cos(deg2rad(latitude)), Math.sin(deg2rad(latitude)), Math.cos(deg2rad(longitude)), Math.sin(deg2rad(longitude)));

问 题

public Cursor dis(String dis, double cos_lat_rad, double sin_lat_rad, double cos_lon_rad, double sin_lon_rad) {

    Cursor cursor = sqLiteDatabase.rawQuery("SELECT * ,(" + sin_lat_rad + "*"sin_lat_rad"+" + cos_lat_rad + "*"cos_lat_rad"*(" + sin_lon_rad + "*"sin_lon_rad"+" + cos_lon_rad + "*"cos_lon_rad")) AS "distance_acos" FROM parish WHERE ("+sin_lat_rad+" * "sin_lat_rad" +"+ cos_lat_rad +"* "cos_lat_rad" * (+"+sin_lon_rad +"* "sin_lon_rad" + "+cos_lon_rad +"* "cos_lon_rad")) >"+dis+ " ORDER BY "distance_acos" DESC ", null);
    return cursor;

}

2. 将距离改为:

 if(c.moveToFirst())
        do {
            double distance_acos= c.getDouble(c.getColumnIndex("distance_acos"));
                     String Distance=String.valueOf(Math.acos(distance_acos) * 6380); 
        }while (c.moveToNext());

窗口:

Install minGw充分选择。 更改环境变量:系统变化途径,包括

c:mingwin

测试功能指挥:

g++ --version

复制文档:延伸功能,c, sqlite3.h, sqlite3ext.h, qlite3 ProgramDirectory。 编写和汇编:

gcc -shared -I "path" -o libsqlitefunctions.so extension-functions.c

(path = qlite3ext.h;即C:sqlite3)

如果该方案得以建立,允许装备延期,则以下工作将:

   sqlite> SELECT load_extension( ./libsqlitefunctions.so );

   sqlite> select cos(radians(45));

   0.707106781186548

SQLite 远程办公 implementation: From: https://www.movable-type.co.uk/scripts/latlong.html https://en.wikipedia.org/wiki/甲型六氯环己烷_formula

远程办公

This uses the ‘haversine’ formula to calculate the great-circle distance between two points – that is, the shortest distance over the earth’s surface – giving an ‘as-the-crow-flies’ distance between the points (ignoring any hills they fly over, of course!).

甲型六氯环己烷

办法:

a = sin²(Δφ/2) + cos φ1 * cos φ2 * sin²(Δλ/2)

c = 2 * atan2( √a, √(1−a) )
c = 2 * 
d = R * c

φ为纬度,λ为长度,R为地球rad(mean radius = 6,371km);

请注意,需要从摩擦中去除三边功能!

Java:

const R = 6378136.6 ; // meters equatorial radius
const φ1 = lat1 * Math.PI/180; // φ, λ in radians
const φ2 = lat2 * Math.PI/180;
const Δφ = (lat2-lat1) * Math.PI/180;
const Δλ = (lon2-lon1) * Math.PI/180;

const a = Math.sin(Δφ/2) * Math.sin(Δφ/2) +
          Math.cos(φ1) * Math.cos(φ2) *
          Math.sin(Δλ/2) * Math.sin(Δλ/2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));

const c = 2 * Math.asen(MIN (1, Math.sqrt(a))); //sqlite implementation

const d = R * c; // in metres

远程办公 = 2 * R * ASIN( MIN (1, SQRT( SIN( (RADIANS(lat1)-RADIANS(lat2))/2 )^2 + COS( RADIANS(lat1) )*COS( RADIANS(lat2) )*SIN( (RADIANS(long1)-RADIANS(long2))/2 )^2 )))

地球物理特性https://en.wikipedia.org/wiki/ Earth_ellipsvil:Ecuatorial radius: 6378.1366 Kms。 平均rad:6367 Kms

Constant = 2 * 6378136.6 = 12756273.2

4. 从下表中找到坐标的弹道:

ROUND (
      12756273.2 * ASIN(
                        MIN (1 , 
                                SQRT(
                                    POWER( SIN(RADIANS(PAR.Lat1 - PAR.Lat2)/2) , 2) + 
                                    COS(RADIANS(PAR.Lat1)) * COS(RADIANS(PAR.Lat2)) * POWER ( SIN(RADIANS(PAR.Long1 - PAR.Long2)/2) , 2)
                                      )
                            )
                        )
         , 0) AS 远程办公

安杰尔的复函并不能解决凯科特的问题,因为安格拉斯仍然包括库马库特不存在的ACOS功能。

我在经过彻底研究后得出的结论是,应当得出粗略估计,以采用以下公式:

估计距离:

SQRT(SQUARE((TO_LAT-FROM_LAT)*110)+
     SQUARE((TO_LONG-FROM_LONG)*COS(TO_LAT)*111)) 




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签