I've got a latitude & longitude of a point. I want all the readings of latitude & longitude within a radius of 500M with respect to that given point. Is any method for that? Is it possible? Is there any algorithm for it?
Asked
Active
Viewed 505 times
0
-
Short Answer: There is no such method available, at present. – Lucifer Feb 26 '14 at 05:29
-
Why don't you use Geofence api android – Mohd Mufiz Feb 26 '14 at 05:33
-
complete solution is at https://developer.android.com/training/location/geofencing.html – Jitesh Upadhyay Feb 26 '14 at 05:37
-
There are infinitely many points on a circle with a radius of 500m - what do you _really_ mean to ask? Do you want to check against a list to see which values fall within a certain distance of a given point? – Floris Feb 27 '14 at 01:47
2 Answers
1
There are many formulas available to calculate the distance between two lat/long points (it won't be exact due to altitude variation, but very close), and filter your sample points based on distance from your given point.
A nice overview of what's available (with math and source code) is available here: http://www.movable-type.co.uk/scripts/latlong.html
Browse through there and pick the distance formula that fits your needs the best.

Jason C
- 38,729
- 14
- 126
- 182
-
You linked my favorite site for this problem; and the point about error due to altitude is a nice one... – Floris Feb 27 '14 at 01:48
0
Here's a solution on StackOverflow for finding the distance between 2 locations, by Usman Kurd
https://stackoverflow.com/a/14394403/2128327
So with a little tweak, we can use his function:
public double getKmDistance(GeoPoint StartP, GeoPoint EndP) {
int Radius=6371;//radius of earth in Km
double lat1 = StartP.getLatitudeE6()/1E6;
double lat2 = EndP.getLatitudeE6()/1E6;
double lon1 = StartP.getLongitudeE6()/1E6;
double lon2 = EndP.getLongitudeE6()/1E6;
double dLat = Math.toRadians(lat2-lat1);
double dLon = Math.toRadians(lon2-lon1);
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2);
double c = 2 * Math.asin(Math.sqrt(a));
double valueResult= Radius*c;
double km=valueResult/1;
DecimalFormat newFormat = new DecimalFormat("####");
kmInDec = Integer.valueOf(newFormat.format(km));
meter=valueResult%1000;
meterInDec= Integer.valueOf(newFormat.format(meter));
Log.i("Radius Value",""+valueResult+" KM "+kmInDec+" Meter "+meterInDec);
return kmInDec;
}
then let's say that you have a list of locations:
ArrayList<GeoPoint> geoPoints = new ArrayList<GeoPoint>();
And we have our current location:
GeoPoint currentLocation = new GeoPoint(..);
then you can do this:
ArrayList<GeoPoint> within500Km = new ArrayList<GeoPoint>();
for (GeoPoint g : geoPoints)
if (getKmDistance(currentLocation, g) <= 500.0)
within500Km.add(g);
for(GeoPoint g : within500Km)
System.out.println("> "+g.getLatitudeE6()+" : "+g.getLongitudeE6()+" ");
-
-
More info from an answer that was really a comment: I am posting a link here because link is not working in comments. https://developer.android.com/training/location/geofencing.html – Michael Durrant Feb 27 '14 at 00:03