如何从靠近我当前位置的arraylist获取latlang?

时间:2016-10-25 07:54:02

标签: android

我有纬度和逻辑列表。整个latlang在ArrayList中可用。如何从靠近我当前位置的arraylist获取latlang?

我目前的位置latlang是 - 40.711991,-73.978543

例如,下面给出整个latlang,它们在ArrayList中可用。

从我的位置,大约100米,跟随latlangs可用。 40.709636,-73.984766 40.717521,-73.980775 40.718757,-73.986268 40.717976,-73.995795 40.716025,-74.000602 40.7304,-73.978286 40.729034,-73.982835 40.730856,-73.992105 40.709128,-74.004378 40.709844,-73.987985

以下latlangs超出100米。 40.715504,-73.922238 40.709193,-73.901296 40.714203,-73.868251 40.683879,-73.875203 40.660704,-73.8831 40.654454,-73.896403

我需要显示ArrayList中的latlang,这些latlang仅接近我当前位置约100米。在100米以外,我不应该表现出来。怎么做 ?请帮忙。在此先感谢。

1 个答案:

答案 0 :(得分:1)

你可以这样做

你必须逐个从arrayList获得lat和long,然后

 //============= for current location ===========
 Location currLoc= new Location("");
 currLoc.setLatitude(currLocLat);
 currLoc.setLongitude(currLocLong);

对arraylist进行迭代,逐个获取lat和long,然后

  //============= for arrayList location ===========
  Location arrListLoc= new Location("");
  arrListLoc.setLatitude(arrLisLat1);
  arrListLoc.setLongitude(arrLisLong1);

您将通过以下方法获得距离:

  float distanceInMeters = currLoc.distanceTo(arrListLoc);
相关问题