<i id='eZve7'><tr id='eZve7'><dt id='eZve7'><q id='eZve7'><span id='eZve7'><b id='eZve7'><form id='eZve7'><ins id='eZve7'></ins><ul id='eZve7'></ul><sub id='eZve7'></sub></form><legend id='eZve7'></legend><bdo id='eZve7'><pre id='eZve7'><center id='eZve7'></center></pre></bdo></b><th id='eZve7'></th></span></q></dt></tr></i><div id='eZve7'><tfoot id='eZve7'></tfoot><dl id='eZve7'><fieldset id='eZve7'></fieldset></dl></div>
    <legend id='eZve7'><style id='eZve7'><dir id='eZve7'><q id='eZve7'></q></dir></style></legend>
      <bdo id='eZve7'></bdo><ul id='eZve7'></ul>

    <tfoot id='eZve7'></tfoot>

    <small id='eZve7'></small><noframes id='eZve7'>

        如何从 SQLite 数据库中的用户位置检索特定范围内

        时间:2023-09-01
      1. <legend id='kYxP0'><style id='kYxP0'><dir id='kYxP0'><q id='kYxP0'></q></dir></style></legend>

      2. <i id='kYxP0'><tr id='kYxP0'><dt id='kYxP0'><q id='kYxP0'><span id='kYxP0'><b id='kYxP0'><form id='kYxP0'><ins id='kYxP0'></ins><ul id='kYxP0'></ul><sub id='kYxP0'></sub></form><legend id='kYxP0'></legend><bdo id='kYxP0'><pre id='kYxP0'><center id='kYxP0'></center></pre></bdo></b><th id='kYxP0'></th></span></q></dt></tr></i><div id='kYxP0'><tfoot id='kYxP0'></tfoot><dl id='kYxP0'><fieldset id='kYxP0'></fieldset></dl></div>

            <bdo id='kYxP0'></bdo><ul id='kYxP0'></ul>
          • <small id='kYxP0'></small><noframes id='kYxP0'>

            <tfoot id='kYxP0'></tfoot>
              <tbody id='kYxP0'></tbody>

                  本文介绍了如何从 SQLite 数据库中的用户位置检索特定范围内的一组位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我的 SQLite 数据库表中存储了一些位置坐标.我想检索距用户当前位置 1 公里范围内的位置.现在我正在从数据库中获取所有值,并编写了一个方法来检索我范围内的值.这给我留下了很大的开销,因为我的表可能包含 1000 多个坐标.

                  I have some location coordinates stored in my SQLite database table. I want to retrieve the locations within 1 km range from the use's current location. Right now I am fetching all values from database and have written a method to retrieve the values within my range. This leaves me great overhead as my table might contain more than 1000 coordinates.

                  所以我正在寻找一种更好的方法来做到这一点.是否可以直接使用 SELECT 查询直接检索我范围内的位置?我发现 问题 1 和 问题 2 但不能找不到可能的解决方法.任何帮助将不胜感激.

                  So i am looking for a better way to do this. Is it possible to directly retrieve locations within my range directly using SELECT query? I found question 1 and question 2 but couldn't find a possible workaround.Any help will be greatly appreciated.

                  这是我现在的 SELECT 查询:

                  This is my SELECT Query now :

                  String selectQuery = "SELECT  "+COLUMN_OBJECTID+","+COLUMN_OBJECTNAME_ENGLISH+"," 
                                        +COLUMN_OBJECTNAME_ARABIC+","+COLUMN_OBJECTLATITUDE+","+COLUMN_OBJECTLONGITUDE+"," 
                                                +COLUMN_OBJECTCATEGORYID+","+COLUMN_OBJECTADDRESS_ENGLISH+","+COLUMN_OBJECTADDRESS_ARABIC 
                                                +" FROM " + TABLE_OBJECTLIST+" WHERE "+COLUMN_OBJECTCATEGORYID+"='"+categoryId+"' AND "+ 
                                                ((userLat-Double.parseDouble(COLUMN_OBJECTLATITUDE))*(userLat-Double.parseDouble(COLUMN_OBJECTLATITUDE)) 
                                                        +(userLong-Double.parseDouble(COLUMN_OBJECTLONGITUDE))*(userLong-Double.parseDouble(COLUMN_OBJECTLONGITUDE))<=range);
                  

                  推荐答案

                  你可以写一个带有以下 where 条件的 SQL 查询:

                  You can write a SQL query with following where condition :

                  where ( (my_lat - LAT)*(my_lat - LAT) + (my_lon - LON)*(my_lon - LON) ) <= 1KM
                  

                  这个想法是使用毕达哥拉斯方法来计算近似位置并在此基础上进行过滤.这里我没有取平方根,因为我猜 SQLite 中的 SQL 函数没有 sqrt.

                  The idea is that use Pythagoras method to calculate approx location and filter based on that. Here I have not taken the square root because I guess SQL functions in SQLite don't have sqrt.

                  这对近似计算很有用...

                  This is good for approximate calculations ...

                  我使用了以下 SQL 并且它工作正常......

                  I used following SQL and it worked ...

                  // Table with columns as String and Float
                  CREATE TABLE "locations" ("id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , "lat_string" VARCHAR, "long_string" VARCHAR, "lat_val" FLOAT, "long_val" FLOAT)
                  
                  // Insert example data
                  INSERT INTO "locations" VALUES(1,'12.9587926','77.7477416',12.9587926,77.7477416);
                  INSERT INTO "locations" VALUES(2,'12.9973486','77.6967362',12.9973486,77.69673619999999);
                  INSERT INTO "locations" VALUES(3,'12.9715987','77.5945627',12.9715987,77.5945627);
                  INSERT INTO "locations" VALUES(4,'12.9629354','77.7122996',12.9629354,77.7122996);
                  
                  // Select when column format is string. This works in SQLIte
                  SELECT id, ( (77.7580827 - long_string)*(77.7580827 - long_string) + (12.9905542 - lat_string)*(12.9905542 - lat_string) ) as dist FROM locations
                  
                  // Select when column format is float. This works in SQLIte
                  SELECT id, ( (77.7580827 - long_val)*(77.7580827 - long_val) + (12.9905542 - lat_val)*(12.9905542 - lat_val) ) as dist FROM locations
                  

                  这篇关于如何从 SQLite 数据库中的用户位置检索特定范围内的一组位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:iOS 5 中来自后台地理围栏的通知? 下一篇:地理定位在 iOS 8 模拟器中不起作用

                  相关文章

                  最新文章

                  <legend id='i0fwN'><style id='i0fwN'><dir id='i0fwN'><q id='i0fwN'></q></dir></style></legend>
                  <tfoot id='i0fwN'></tfoot>

                  <small id='i0fwN'></small><noframes id='i0fwN'>

                    <i id='i0fwN'><tr id='i0fwN'><dt id='i0fwN'><q id='i0fwN'><span id='i0fwN'><b id='i0fwN'><form id='i0fwN'><ins id='i0fwN'></ins><ul id='i0fwN'></ul><sub id='i0fwN'></sub></form><legend id='i0fwN'></legend><bdo id='i0fwN'><pre id='i0fwN'><center id='i0fwN'></center></pre></bdo></b><th id='i0fwN'></th></span></q></dt></tr></i><div id='i0fwN'><tfoot id='i0fwN'></tfoot><dl id='i0fwN'><fieldset id='i0fwN'></fieldset></dl></div>
                    • <bdo id='i0fwN'></bdo><ul id='i0fwN'></ul>