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

<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="qwawimqqmiuu" id='eMpH3'><tfoot id='eMpH3'></tfoot><dl id='eMpH3'><fieldset id='eMpH3'></fieldset></dl></div>

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

        如何在Android中根據(jù)與當(dāng)前位置的距離對(duì)地理點(diǎn)進(jìn)

        How to Sort Geo-points according to the distance from current location in Android(如何在Android中根據(jù)與當(dāng)前位置的距離對(duì)地理點(diǎn)進(jìn)行排序)
        <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="qwawimqqmiuu" id='sCY3T'><tfoot id='sCY3T'></tfoot><dl id='sCY3T'><fieldset id='sCY3T'></fieldset></dl></div>

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

                • 本文介紹了如何在Android中根據(jù)與當(dāng)前位置的距離對(duì)地理點(diǎn)進(jìn)行排序的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我有一個(gè)Place"對(duì)象,每個(gè)對(duì)象都有一個(gè) LatLng 坐標(biāo):

                  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);
                  

                  如何根據(jù)離我最近的對(duì)象對(duì)這些對(duì)象進(jìn)行排序?感謝您的幫助

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

                  推薦答案

                  從 this answer 來(lái)自@shieldstroy 發(fā)布的問(wèn)題,它使用 大圓距離,我得到了這個(gè)例子.

                  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;
                      }
                  }
                  

                  這是高級(jí)代碼,我只是把它放在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
                  

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

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

                  相關(guān)文檔推薦

                  Help calculating X and Y from Latitude and Longitude in iPhone(幫助從 iPhone 中的緯度和經(jīng)度計(jì)算 X 和 Y)
                  Get user#39;s current location using GPS(使用 GPS 獲取用戶的當(dāng)前位置)
                  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 返回負(fù)速度)
                  How to detect Location Provider ? GPS or Network Provider(如何檢測(cè)位置提供者?GPS 或網(wǎng)絡(luò)提供商)
                      <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="qwawimqqmiuu" 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'>

                          • 主站蜘蛛池模板: 日本特黄a级高清免费大片 特黄色一级毛片 | 91精品国产91久久久久青草 | 国产四区 | 欧美videosex性极品hd | 国产午夜精品一区二区三区嫩草 | 欧美国产激情二区三区 | 亚洲精品中文字幕中文字幕 | 91欧美| 国产97在线看 | 黄色男女网站 | 一级黄色片日本 | 伊人免费网| 日本三级日产三级国产三级 | 成人在线观看中文字幕 | 毛片电影| 一区二区在线观看av | 国产成人精品午夜视频免费 | 亚洲成人福利在线观看 | 中文字幕一级 | 国产成人精品视频在线观看 | 91传媒在线观看 | 久久精品久久久久久 | 久久一区| 亚州精品天堂中文字幕 | 91免费观看| 乱码av午夜噜噜噜噜动漫 | 成人福利网 | 免费小视频在线观看 | 99热精品在线观看 | 欧美三区在线观看 | 国产精品国产成人国产三级 | 亚洲国产一 | 欧美日韩在线免费 | 亚洲视频三区 | 日韩在线视频一区二区三区 | 中文一区二区视频 | 国产一级电影在线观看 | 成年人视频在线免费观看 | 喷水毛片 | 国产高清亚洲 | 国产婷婷综合 |