How to show Locations those are within 2 miles from my current Location, i am using below code which allow me to get distance of few locations from my current location in Miles...
but now i want to know, which condition i need to write if i want my app to show locations within 2 miles ?
public void distanceBetweenTwoLocations() {
Location currentLocation = new Location("");
currentLocation.setLatitude(latitude);
currentLocation.setLongitude(longitude);
for (int i = 0; i < actorsList.size(); i++) {
locations = (Locations) actorsList.get(i);
Location destinationLocation = new Location(" ");
destinationLocation.setLatitude(Double.valueOf(actorsList.get(i).getLatitude()));
destinationLocation.setLongitude(Double.valueOf(actorsList.get(i).getLongitude()));
double inMeters = currentLocation.distanceTo(destinationLocation);
double inKms = inMeters / 1000;
double inMiles = inKms * 0.000621371;
DecimalFormat df = new DecimalFormat("#.##");
locations.setDistance(df.format(inMiles));
}
}
0 comments:
Post a Comment