Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if marker is inside circle radius

I'm trying to know if a given marker is inside a circle radius.

In javascript, i can do something like:

google.maps.geometry.spherical.computeDistanceBetween(latLngCircleCenter, latLngPoint);

But in android, using maps-v2, i'm stucked.

enter image description here

like image 278
Otuyh Avatar asked Apr 18 '13 12:04

Otuyh


1 Answers

After a lot of research, i found a very simple solution:

float[] distance = new float[2];

Location.distanceBetween( marker.getPosition().latitude, marker.getPosition().longitude,
    circle.getCenter().latitude, circle.getCenter().longitude, distance);

if( distance[0] > circle.getRadius()  ){
    Toast.makeText(getBaseContext(), "Outside", Toast.LENGTH_LONG).show();
} else {
    Toast.makeText(getBaseContext(), "Inside", Toast.LENGTH_LONG).show();
}

I'm testing this and it's working. Can someone test too and give the feedback here?

like image 124
Otuyh Avatar answered Sep 19 '22 06:09

Otuyh