我想知道给定的标记是否在圆半径内。
在javascript中,我可以这样做:
google.maps.geometry.spherical.computeDistanceBetween(latLngCircleCenter, latLngPoint);
但在android中,使用maps v2时,我被卡住了。
发布于 2013-04-19 01:26:02
经过大量的研究,我找到了一个非常简单的解决方案:
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();
}
我正在测试它,它正在工作。有人可以在这里测试并给出反馈吗?
发布于 2013-06-11 18:46:34
你可以在这里找到你在Javascript中使用的同样的API:https://github.com/googlemaps/android-maps-utils/blob/master/library/src/com/google/maps/android/SphericalUtil.java
发布于 2013-04-18 20:30:10
我认为找到圆的中心是可能的,你在你的代码中定义了一个给定的地理点的圆。您可以将其保存并在以后使用。然后尝试 Location.distanceBetween(..)
https://stackoverflow.com/questions/16082622
复制相似问题