Detect if a point on a map is inside a circle [closed]

0

Someone knows if it is possible to detect if a point with latitude and longitude is inside a circle. All this developed on Android.

    
asked by Antonio Marquez Jorge 18.03.2016 в 00:55
source

1 answer

2

In Android is there any type of object to store GPS position?

link

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

link

 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

link

link

    
answered by 18.03.2016 / 05:17
source