Someone knows if it is possible to detect if a point with latitude and longitude is inside a circle. All this developed on Android.
Someone knows if it is possible to detect if a point with latitude and longitude is inside a circle. All this developed on Android.
In Android is there any type of object to store GPS position?
LatLng pos = new LatLng(40.416775, -3.703790);
double lat = pos.latitude; //getLatitude
double lng = pos.longitude;//getLongitude
Suppose that this is your point pos
GoogleMap map;
// ... get a map.
// Add a circle in Sydney
Circle circle = map.addCircle(new CircleOptions()
.center(new LatLng(-33.87365, 151.20689))
.radius(10000)
.strokeColor(Color.RED)
.fillColor(Color.BLUE));
if this were your circle circle
(it's from the Sydney Australia example in the top link)
link , double, double, double, float [])
float[] disResultado = new float[2];
Location.distanceBetween( pos.latitude, pos.longitude,
circle.getCenter().latitude,
circle.getCenter().longitude,
disResultado);
if(disResultado[0] > circle.getRadius()){
Log Fuera
} else {
Log Dentro
}
You can use the class Location
to make the calculations