我想知道一个给定的标记是否在圆的半径内。
在JavaScript中,我可以这样做:
google.maps.geometry.spherical.computeDistanceBetween(latLngCircleCenter, latLngPoint);
但在Android中,使用maps-v2时,我卡住了。
我想知道一个给定的标记是否在圆的半径内。
在JavaScript中,我可以这样做:
google.maps.geometry.spherical.computeDistanceBetween(latLngCircleCenter, latLngPoint);
但在Android中,使用maps-v2时,我卡住了。
经过大量研究,我找到了一个非常简单的解决方案:
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();
}
我正在测试这个,并且它能够工作。有人也可以测试一下并在此处提供反馈吗?
在这里,您可以使用与JavaScript相同的API来进行Android编程:https://github.com/googlemaps/android-maps-utils/blob/master/library/src/com/google/maps/android/SphericalUtil.java