0

I am having list of Latitude and logitudes. Entire latlang is available in the ArrayList. How to get latlangs from the arraylist which are near to my current location ?

My current location latlang is - 40.711991 , -73.978543

For Example, below Given the entire latlangs, which is available in the ArrayList.

From my location, Around 100 meter, following latlangs are available. 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

Following latlangs are out of 100 meter. 40.715504 , -73.922238 40.709193 , -73.901296 40.714203 , -73.868251 40.683879 , -73.875203 40.660704 , -73.8831 40.654454 , -73.896403

I need to show latlangs from the ArrayList which are close to my current location around 100 meter only. Out of 100 meter, I should not show. How to do that ? Kindly please help. Thanks in Advance.

1 Answers1

1

You can do like

You have to get lat and long one by one from arrayList and then

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

Do iteration over arraylist, fetch one by one lat and longs and then,

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

You will get distance in meter by following method..

  float distanceInMeters = currLoc.distanceTo(arrListLoc);
Vijay
  • 156
  • 1
  • 14