久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <small id='WdwwP'></small><noframes id='WdwwP'>

      <bdo id='WdwwP'></bdo><ul id='WdwwP'></ul>

    1. <legend id='WdwwP'><style id='WdwwP'><dir id='WdwwP'><q id='WdwwP'></q></dir></style></legend>
      1. <i id='WdwwP'><tr id='WdwwP'><dt id='WdwwP'><q id='WdwwP'><span id='WdwwP'><b id='WdwwP'><form id='WdwwP'><ins id='WdwwP'></ins><ul id='WdwwP'></ul><sub id='WdwwP'></sub></form><legend id='WdwwP'></legend><bdo id='WdwwP'><pre id='WdwwP'><center id='WdwwP'></center></pre></bdo></b><th id='WdwwP'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='WdwwP'><tfoot id='WdwwP'></tfoot><dl id='WdwwP'><fieldset id='WdwwP'></fieldset></dl></div>
      2. <tfoot id='WdwwP'></tfoot>
      3. SQlite 獲取最近的位置(經緯度)

        SQlite Getting nearest locations (with latitude and longitude)(SQlite 獲取最近的位置(經緯度))

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

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

              <tfoot id='WIlVp'></tfoot><legend id='WIlVp'><style id='WIlVp'><dir id='WIlVp'><q id='WIlVp'></q></dir></style></legend>
                <tbody id='WIlVp'></tbody>
                  <bdo id='WIlVp'></bdo><ul id='WIlVp'></ul>

                  本文介紹了SQlite 獲取最近的位置(經緯度)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我的 SQLite 數據庫中存儲了經緯度數據,我想獲取與我輸入的參數最近的位置(例如,我當前的位置 - 緯度/經度等).

                  我知道這在 MySQL 中是可能的,并且我已經進行了相當多的研究,認為 SQLite 需要一個自定義外部函數用于 Haversine 公式(計算球體上的距離),但我還沒有找到任何寫在Java 和作品.

                  另外,如果我想添加自定義函數,我需要 org.sqlite .jar(用于 org.sqlite.Function),這會增加不必要的大小應用程序.

                  另一方面,我需要 SQL 中的 Order by 函數,因為僅顯示距離并不是什么大問題 - 我已經在自定義 SimpleCursorAdapter 中做到了,但我無法對數據進行排序,因為我的數據庫中沒有距離列.這意味著每次位置更改時都要更新數據庫,這是對電池和性能的浪費.因此,如果有人對使用不在數據庫中的列對光標進行排序有任何想法,我也將不勝感激!

                  我知道有大量的 Android 應用程序使用此功能,但誰能解釋一下它的魔力.

                  順便說一句,我找到了這個替代方案:并完成了它.

                  I have data with latitude and longitude stored in my SQLite database, and I want to get the nearest locations to the parameters I put in (ex. My current location - lat/lng, etc.).

                  I know that this is possible in MySQL, and I've done quite some research that SQLite needs a custom external function for the Haversine formula (calculating distance on a sphere), but I haven't found anything that is written in Java and works.

                  Also, if I want to add custom functions, I need the org.sqlite .jar (for org.sqlite.Function), and that adds unnecessary size to the app.

                  The other side of this is, I need the Order by function from SQL, because displaying the distance alone isn't that much of a problem - I already did it in my custom SimpleCursorAdapter, but I can't sort the data, because I don't have the distance column in my database. That would mean updating the database every time the location changes and that's a waste of battery and performance. So if someone has any idea on sorting the cursor with a column that's not in the database, I'd be grateful too!

                  I know there are tons of Android apps out there that use this function, but can someone please explain the magic.

                  By the way, I found this alternative: Query to get records based on Radius in SQLite?

                  It's suggesting to make 4 new columns for cos and sin values of lat and lng, but is there any other, not so redundant way?

                  解決方案

                  1) At first filter your SQLite data with a good approximation and decrease amount of data that you need to evaluate in your java code. Use the following procedure for this purpose:

                  To have a deterministic threshold and more accurate filter on data, It is better to calculate 4 locations that are in radius meter of the north, west, east and south of your central point in your java code and then check easily by less than and more than SQL operators (>, <) to determine if your points in database are in that rectangle or not.

                  The method calculateDerivedPosition(...) calculates those points for you (p1, p2, p3, p4 in picture).

                  /**
                  * Calculates the end-point from a given source at a given range (meters)
                  * and bearing (degrees). This methods uses simple geometry equations to
                  * calculate the end-point.
                  * 
                  * @param point
                  *           Point of origin
                  * @param range
                  *           Range in meters
                  * @param bearing
                  *           Bearing in degrees
                  * @return End-point from the source given the desired range and bearing.
                  */
                  public static PointF calculateDerivedPosition(PointF point,
                              double range, double bearing)
                      {
                          double EarthRadius = 6371000; // m
                  
                          double latA = Math.toRadians(point.x);
                          double lonA = Math.toRadians(point.y);
                          double angularDistance = range / EarthRadius;
                          double trueCourse = Math.toRadians(bearing);
                  
                          double lat = Math.asin(
                                  Math.sin(latA) * Math.cos(angularDistance) +
                                          Math.cos(latA) * Math.sin(angularDistance)
                                          * Math.cos(trueCourse));
                  
                          double dlon = Math.atan2(
                                  Math.sin(trueCourse) * Math.sin(angularDistance)
                                          * Math.cos(latA),
                                  Math.cos(angularDistance) - Math.sin(latA) * Math.sin(lat));
                  
                          double lon = ((lonA + dlon + Math.PI) % (Math.PI * 2)) - Math.PI;
                  
                          lat = Math.toDegrees(lat);
                          lon = Math.toDegrees(lon);
                  
                          PointF newPoint = new PointF((float) lat, (float) lon);
                  
                          return newPoint;
                  
                      }
                  

                  And now create your query:

                  PointF center = new PointF(x, y);
                  final double mult = 1; // mult = 1.1; is more reliable
                  PointF p1 = calculateDerivedPosition(center, mult * radius, 0);
                  PointF p2 = calculateDerivedPosition(center, mult * radius, 90);
                  PointF p3 = calculateDerivedPosition(center, mult * radius, 180);
                  PointF p4 = calculateDerivedPosition(center, mult * radius, 270);
                  
                  strWhere =  " WHERE "
                          + COL_X + " > " + String.valueOf(p3.x) + " AND "
                          + COL_X + " < " + String.valueOf(p1.x) + " AND "
                          + COL_Y + " < " + String.valueOf(p2.y) + " AND "
                          + COL_Y + " > " + String.valueOf(p4.y);
                  

                  COL_X is the name of the column in the database that stores latitude values and COL_Y is for longitude.

                  So you have some data that are near your central point with a good approximation.

                  2) Now you can loop on these filtered data and determine if they are really near your point (in the circle) or not using the following methods:

                  public static boolean pointIsInCircle(PointF pointForCheck, PointF center,
                              double radius) {
                          if (getDistanceBetweenTwoPoints(pointForCheck, center) <= radius)
                              return true;
                          else
                              return false;
                      }
                  
                  public static double getDistanceBetweenTwoPoints(PointF p1, PointF p2) {
                          double R = 6371000; // m
                          double dLat = Math.toRadians(p2.x - p1.x);
                          double dLon = Math.toRadians(p2.y - p1.y);
                          double lat1 = Math.toRadians(p1.x);
                          double lat2 = Math.toRadians(p2.x);
                  
                          double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2)
                                  * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
                          double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
                          double d = R * c;
                  
                          return d;
                      }
                  

                  Enjoy!

                  I used and customized this reference and completed it.

                  這篇關于SQlite 獲取最近的位置(經緯度)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)
                    <tbody id='2SrwC'></tbody>
                    <bdo id='2SrwC'></bdo><ul id='2SrwC'></ul>

                      1. <legend id='2SrwC'><style id='2SrwC'><dir id='2SrwC'><q id='2SrwC'></q></dir></style></legend>
                        <i id='2SrwC'><tr id='2SrwC'><dt id='2SrwC'><q id='2SrwC'><span id='2SrwC'><b id='2SrwC'><form id='2SrwC'><ins id='2SrwC'></ins><ul id='2SrwC'></ul><sub id='2SrwC'></sub></form><legend id='2SrwC'></legend><bdo id='2SrwC'><pre id='2SrwC'><center id='2SrwC'></center></pre></bdo></b><th id='2SrwC'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='2SrwC'><tfoot id='2SrwC'></tfoot><dl id='2SrwC'><fieldset id='2SrwC'></fieldset></dl></div>

                            <small id='2SrwC'></small><noframes id='2SrwC'>

                            <tfoot id='2SrwC'></tfoot>
                          • 主站蜘蛛池模板: 91一区二区在线观看 | 久久四虎 | 麻豆国产一区二区三区四区 | 中文字幕亚洲区一区二 | 国产欧美日韩精品一区 | 国产精品久久久久久久久久三级 | 欧美亚洲国语精品一区二区 | 国产精品一区二区久久 | 国产黄色一级电影 | 四虎影音 | 精品国产欧美一区二区三区成人 | 免费观看黄色片视频 | 成人在线免费视频观看 | 久久精品在线 | 免费观看www7722午夜电影 | 国产一区二区三区四区五区加勒比 | 国产精品久久久 | 国产日韩欧美另类 | 亚洲综合小视频 | 在线观看国产 | 久久精品69 | 影音先锋欧美资源 | 成人黄色网址大全 | 久久久片| 99精品欧美一区二区三区综合在线 | 毛片免费观看视频 | 国产一区二区在线视频 | 香蕉av免费 | 91社区在线高清 | 亚州无限乱码 | 国产成人a亚洲精品 | 国产高清视频一区 | 亚洲成人av | 奇米影视首页 | 伊人春色成人网 | 国产97在线视频 | aaaaa毛片 | 婷婷在线视频 | 日韩欧美二区 | 国产欧美精品区一区二区三区 | 中文字幕久久久 |