pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<legend id='eMpH3'><style id='eMpH3'><dir id='eMpH3'><q id='eMpH3'></q></dir></style></legend>
  • <small id='eMpH3'></small><noframes id='eMpH3'>

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

      1. <tfoot id='eMpH3'></tfoot>

        如何在Android中根據與當前位置的距離對地理點進

        How to Sort Geo-points according to the distance from current location in Android(如何在Android中根據與當前位置的距離對地理點進行排序)
        <tfoot id='sCY3T'></tfoot>

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

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

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

                • 本文介紹了如何在Android中根據與當前位置的距離對地理點進行排序的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個Place"對象,每個對象都有一個 LatLng 坐標:

                  I have a "Place" object with a LatLng coordinate for each:

                  import com.google.android.gms.maps.model.LatLng;
                  
                  public class Place{
                      public String name;
                      public LatLng latlng;
                  
                      public Restaurant(String name, LatLng latlng) {
                          this.name = name;
                          this.latlng = latlng;
                      }
                  }
                  

                  我有這些地方的 ArrayList,如下所示:

                  and I have an ArrayList of these Places, something like this:

                      ArrayList<Place> places = new ArrayList<Place>();
                      places.add("Place 1", LatLng(90.0,90.0));
                      places.add("Place 2", LatLng(93.0,93.0));
                      places.add("Place 3", LatLng(83.0,92.0));
                      places.add("Place 4", LatLng(93.0,91.0));
                  

                  我有我的"LatLng:

                  and I have "my" LatLng:

                      LatLng myLocation = new LatLng(10.0,10.0);
                  

                  如何根據離我最近的對象對這些對象進行排序?感謝您的幫助

                  How can I sort these objects according to closest to me? Thanks for the help

                  推薦答案

                  從 this answer 來自@shieldstroy 發布的問題,它使用 大圓距離,我得到了這個例子.

                  Taking the algorithm from this answer from the question posted by @shieldstroy, that uses the Great Circle Distance, I got this example working.

                  這里是比較器:

                  public class SortPlaces implements Comparator<Place> {
                      LatLng currentLoc;
                  
                      public SortPlaces(LatLng current){
                          currentLoc = current;
                      }
                      @Override
                      public int compare(final Place place1, final Place place2) {
                          double lat1 = place1.latlng.latitude;
                          double lon1 = place1.latlng.longitude;
                          double lat2 = place2.latlng.latitude;
                          double lon2 = place2.latlng.longitude;
                  
                          double distanceToPlace1 = distance(currentLoc.latitude, currentLoc.longitude, lat1, lon1);
                          double distanceToPlace2 = distance(currentLoc.latitude, currentLoc.longitude, lat2, lon2);
                          return (int) (distanceToPlace1 - distanceToPlace2);
                      }
                  
                      public double distance(double fromLat, double fromLon, double toLat, double toLon) {
                          double radius = 6378137;   // approximate Earth radius, *in meters*
                          double deltaLat = toLat - fromLat;
                          double deltaLon = toLon - fromLon;
                          double angle = 2 * Math.asin( Math.sqrt(
                                  Math.pow(Math.sin(deltaLat/2), 2) +
                                          Math.cos(fromLat) * Math.cos(toLat) *
                                                  Math.pow(Math.sin(deltaLon/2), 2) ) );
                          return radius * angle;
                      }
                  }
                  

                  這是高級代碼,我只是把它放在onCreate()中:

                  Here is the high level code, I just put this in onCreate():

                          //My location, San Francisco
                          double lat = 37.77657;
                          double lng = -122.417506;
                          LatLng latLng = new LatLng(lat, lng);
                  
                          //set up list
                          ArrayList<Place> places = new ArrayList<Place>();
                  
                          places.add(new Place("New York", new LatLng(40.571256,73.98369)));
                          places.add(new Place("Colorado", new LatLng(39.260658,-105.101615)));
                          places.add(new Place("Los Angeles", new LatLng(33.986816,118.473819)));
                  
                          for (Place p: places){
                              Log.i("Places before sorting", "Place: " + p.name);
                          }
                  
                          //sort the list, give the Comparator the current location
                          Collections.sort(places, new SortPlaces(latLng));
                  
                          for (Place p: places){
                              Log.i("Places after sorting", "Place: " + p.name);
                          }
                  

                  這是日志輸出:

                  04-17 23:04:16.074  12963-12963/com.maptest.daniel.maptest I/Places before sorting﹕ Place: New York
                  04-17 23:04:16.074  12963-12963/com.maptest.daniel.maptest I/Places before sorting﹕ Place: Colorado
                  04-17 23:04:16.074  12963-12963/com.maptest.daniel.maptest I/Places before sorting﹕ Place: Los Angeles
                  04-17 23:04:16.074  12963-12963/com.maptest.daniel.maptest I/Places after sorting﹕ Place: Los Angeles
                  04-17 23:04:16.074  12963-12963/com.maptest.daniel.maptest I/Places after sorting﹕ Place: Colorado
                  04-17 23:04:16.074  12963-12963/com.maptest.daniel.maptest I/Places after sorting﹕ Place: New York
                  

                  這篇關于如何在Android中根據與當前位置的距離對地理點進行排序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  Help calculating X and Y from Latitude and Longitude in iPhone(幫助從 iPhone 中的緯度和經度計算 X 和 Y)
                  Get user#39;s current location using GPS(使用 GPS 獲取用戶的當前位置)
                  IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                  How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                  CLLocation returning negative speed(CLLocation 返回負速度)
                  How to detect Location Provider ? GPS or Network Provider(如何檢測位置提供者?GPS 或網絡提供商)
                      <bdo id='dNZTF'></bdo><ul id='dNZTF'></ul>
                      <i id='dNZTF'><tr id='dNZTF'><dt id='dNZTF'><q id='dNZTF'><span id='dNZTF'><b id='dNZTF'><form id='dNZTF'><ins id='dNZTF'></ins><ul id='dNZTF'></ul><sub id='dNZTF'></sub></form><legend id='dNZTF'></legend><bdo id='dNZTF'><pre id='dNZTF'><center id='dNZTF'></center></pre></bdo></b><th id='dNZTF'></th></span></q></dt></tr></i><div class="3biokuh" id='dNZTF'><tfoot id='dNZTF'></tfoot><dl id='dNZTF'><fieldset id='dNZTF'></fieldset></dl></div>
                      • <tfoot id='dNZTF'></tfoot>

                            <tbody id='dNZTF'></tbody>

                        1. <legend id='dNZTF'><style id='dNZTF'><dir id='dNZTF'><q id='dNZTF'></q></dir></style></legend>

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

                          • 主站蜘蛛池模板: 铝板冲孔网,不锈钢冲孔网,圆孔冲孔网板,鳄鱼嘴-鱼眼防滑板,盾构走道板-江拓数控冲孔网厂-河北江拓丝网有限公司 | 合肥活动房_安徽活动板房_集成打包箱房厂家-安徽玉强钢结构集成房屋有限公司 | 无锡市珂妮日用化妆品有限公司|珂妮日化官网|洗手液厂家 | 废水处理-废气处理-工业废水处理-工业废气处理工程-深圳丰绿环保废气处理公司 | 粉碎机_塑料粉碎机_塑料破碎机厂家-星标机械 | 上海平衡机-单面卧式动平衡机-万向节动平衡机-圈带动平衡机厂家-上海申岢动平衡机制造有限公司 | 领袖户外_深度旅游、摄影旅游、小团慢旅行、驴友网 | 台式恒温摇床价格_大容量恒温摇床厂家-上海量壹科学仪器有限公司 | 台式核磁共振仪,玻璃软化点测定仪,旋转高温粘度计,测温锥和测温块-上海麟文仪器 | 上海电子秤厂家,电子秤厂家价格,上海吊秤厂家,吊秤供应价格-上海佳宜电子科技有限公司 | 2-羟基泽兰内酯-乙酰蒲公英萜醇-甘草查尔酮A-上海纯优生物科技有限公司 | 浴室柜-浴室镜厂家-YINAISI · 意大利设计师品牌 | 咿耐斯 |-浙江台州市丰源卫浴有限公司 | 无味渗透剂,泡沫抑尘剂,烷基糖苷-威海威能化工有限公司 | 厦门网站建设_厦门网站设计_小程序开发_网站制作公司【麦格科技】 | 硅胶管挤出机厂家_硅胶挤出机生产线_硅胶条挤出机_臣泽智能装备 贵州科比特-防雷公司厂家提供贵州防雷工程,防雷检测,防雷接地,防雷设备价格,防雷产品报价服务-贵州防雷检测公司 | 彭世修脚_修脚加盟_彭世修脚加盟_彭世足疗加盟_足疗加盟连锁_彭世修脚技术培训_彭世足疗 | 档案密集架_电动密集架_移动密集架_辽宁档案密集架-盛隆柜业厂家现货批发销售价格公道 | 进口消泡剂-道康宁消泡剂-陶氏消泡剂-大洋消泡剂 | 智能电表|预付费ic卡水电表|nb智能无线远传载波电表-福建百悦信息科技有限公司 | 巨野月嫂-家政公司-巨野县红墙安康母婴护理中心 | 屏蔽泵厂家,化工屏蔽泵_维修-淄博泵业 | 耐高温风管_耐高温软管_食品级软管_吸尘管_钢丝软管_卫生级软管_塑料波纹管-东莞市鑫翔宇软管有限公司 | 固诺家居-全屋定制十大品牌_整体衣柜木门橱柜招商加盟 | 精密光学实验平台-红外粉末压片机模具-天津博君 | 温州中研白癜风专科_温州治疗白癜风_温州治疗白癜风医院哪家好_温州哪里治疗白癜风 | 线粒体膜电位荧光探针-细胞膜-标记二抗-上海复申生物科技有限公司 | 充气膜专家-气膜馆-PTFE膜结构-ETFE膜结构-商业街膜结构-奥克金鼎 | 北京环球北美考试院【官方网站】|北京托福培训班|北京托福培训 | 广东燎了网络科技有限公司官网-网站建设-珠海网络推广-高端营销型外贸网站建设-珠海专业h5建站公司「了了网」 | 连续密炼机_双转子连续密炼机_连续式密炼机-南京永睿机械制造有限公司 | 金属抛光机-磁悬浮抛光机-磁力研磨机-磁力清洗机 - 苏州冠古科技 | 济南冷库安装-山东冷库设计|建造|冷库维修-山东齐雪制冷设备有限公司 | 闪电优家-卫生间防水补漏_酒店漏水渗水维修_防水堵漏公司 | 智慧食堂_食堂管理系统_食堂订餐_食堂消费系统—客易捷 | 上海阳光泵业制造有限公司 -【官方网站】 | 冰晶石|碱性嫩黄闪蒸干燥机-有机垃圾烘干设备-草酸钙盘式干燥机-常州市宝康干燥 | 塑料检查井_双扣聚氯乙烯增强管_双壁波纹管-河南中盈塑料制品有限公司 | 四探针电阻率测试仪-振实密度仪-粉末流动性测定仪-宁波瑞柯微智能 | 广州小程序开发_APP开发公司_分销商城系统定制_小跑科技 | 武汉高低温试验机-现货恒温恒湿试验箱-高低温湿热交变箱价格-湖北高天试验设备 | 武汉刮刮奖_刮刮卡印刷厂_为企业提供门票印刷_武汉合格证印刷_现金劵代金券印刷制作 - 武汉泽雅印刷有限公司 |