检查标记是圆的半径内半径、标记

2023-09-05 06:52:19 作者:害怕被欺骗

我想知道,如果给定的标志物是一个圆的半径内。

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

在JavaScript中,我可以这样做:

In javascript, i can do something like:

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

但在Android中,利用地图-V2,我是stucked。

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

推荐答案

大量的调查研究后,我发现了一个很简单的解决办法:

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?